package com.yunxi.service.dubboService.impl;

import com.aiways.center.order.api.IOrderApi;
import com.aiways.center.order.api.IRefundApi;
import com.aiways.center.order.api.IReturnApi;
import com.aiways.center.order.api.dto.request.*;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dtyunxi.rest.RestResponse;
import com.github.pagehelper.PageInfo;
import com.yunxi.activiti.pojo.ActivitiRecordVO;
import com.yunxi.activiti.pojo.ActivitiResult;
import com.yunxi.activiti.pojo.ActivitiTaskVO;
import com.yunxi.activiti.service.ActivitiManageDubboService;
import com.yunxi.baseDataToHub.pojo.app.AppLittleOrderAuditVO;
import com.yunxi.baseDataToHub.pojo.app.AuditRecordVO;
import com.yunxi.baseDataToHub.pojo.app.OrderStatusVO;
import com.yunxi.baseDataToHub.pojo.urm.OrderInformationTransmissionVO;
import com.yunxi.baseDataToHub.service.app.AppDubboService;
import com.yunxi.baseDataToHub.service.urm.UrmDubboService;
import com.yunxi.bizToBaseData.pojo.DictVO;
import com.yunxi.bizToBaseData.service.Dict2BizDubboService;
import com.yunxi.core.base.Constant;
import com.yunxi.core.enums.DMSEnumsEntity;
import com.yunxi.core.util.BeanTools;
import com.yunxi.core.util.DateUtil;
import com.yunxi.core.util.GUIDGenerator;
import com.yunxi.core.util.WgrDate;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.DictConstant;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.customer.pojo.CustomCreditReportingVO;
import com.yunxi.customer.pojo.CustomerVO;
import com.yunxi.customer.service.CustomCreditReportingDubboService;
import com.yunxi.customer.service.CustomerDubboService;
import com.yunxi.dealer.pojo.PartnerVO;
import com.yunxi.dealer.service.AreaManagerDubboService;
import com.yunxi.dealer.service.PartnerDubboService;
import com.yunxi.hubToBiz.pojo.CancelVOAPP;
import com.yunxi.hubToBiz.pojo.OrderActualSalesRespVO;
import com.yunxi.hubToBiz.service.App2PmsDubboService;
import com.yunxi.model.order.OrderCustomer;
import com.yunxi.model.order.OrderVehicle;
import com.yunxi.model.order.TrRefund;
import com.yunxi.model.sto.VehicleOffline;
import com.yunxi.order.pojo.*;
import com.yunxi.order.service.OrderCustomerDetailDubboService;
import com.yunxi.order.service.OrderCustomerDubboService;
import com.yunxi.order.service.OrderCustomerFeatureDubboService;
import com.yunxi.order.service.OrderOemManagerDubboService;
import com.yunxi.sat.pojo.HandleVehicleVO;
import com.yunxi.sat.pojo.SatCustomerClueVO;
import com.yunxi.sat.pojo.SatMessAddVO;
import com.yunxi.sat.service.MsgTemplateDubboService;
import com.yunxi.sat.service.SatCustomerClueDubboService;
import com.yunxi.sat.service.SatCustomerFollowDubboService;
import com.yunxi.sat.service.SatMessDubboService;
import com.yunxi.service.localService.OrderCustomerService;
import com.yunxi.service.localService.OrderVehicleService;
import com.yunxi.service.localService.TrRefundService;
import com.yunxi.service.localService.impl.CodeCreateServiceImpl;
import com.yunxi.service.localService.sat.HandleVehicleService;
import com.yunxi.service.localService.sat.SatMessService;
import com.yunxi.sto.pojo.StoStockReturnInVO;
import com.yunxi.sto.pojo.VehicleOfflineVO;
import com.yunxi.sto.pojo.VehicleStockBindVO;
import com.yunxi.sto.service.StoStockInPlanDubboService;
import com.yunxi.sto.service.VehicleOfflineDubboService;
import com.yunxi.sto.service.VehiclePdiBillDubboService;
import com.yunxi.sto.service.VehicleStockDubboService;
import com.yunxi.sys.pojo.AreaVO;
import com.yunxi.sys.pojo.StaffVO;
import com.yunxi.sys.service.AreaDubboService;
import com.yunxi.sys.service.AttachDubboService;
import com.yunxi.sys.service.StaffDubboService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>
 * 零售订单 服务实现类
 * </p>PARTNER_CODE
 *
 * @author
 * @since 2019-05-29
 */
public class OrderCustomerDubboServiceImpl implements OrderCustomerDubboService, App2PmsDubboService {

   @Autowired
   @Qualifier(value = "orderCustomerServiceImpl")
   OrderCustomerService orderCustomerService;

   @Autowired
   OrderCustomerDetailDubboService orderCustomerDetailDubboServiceImpl;

   @Autowired
   OrderCustomerFeatureDubboService orderCustomerFeatureDubboServiceImpl;

   @Autowired
   VehicleOfflineDubboService vehicleOfflineDubboServiceImpl;

   @Autowired
   private OrderOemManagerDubboService orderOemManagerDubboServiceImpl;

   @Autowired
   VehiclePdiBillDubboService vehiclePdiBillDubboService;

   @Autowired
   VehicleStockDubboService vehicleStockDubboService;

   @Autowired
   @Qualifier(value = "orderVehicleServiceImpl")
   OrderVehicleService orderVehicleService;

   @Autowired
   @Qualifier(value = "vehicleOfflineDubboServiceImpl")
   VehicleOfflineDubboService  vehicleOfflineDubboService;

   @Autowired
   IOrderApi orderApi;

   @Autowired
   IRefundApi refundApi;

   @Autowired
   IReturnApi returnApi;

   @Autowired
   @Qualifier("codeCreateServiceImpl")
   CodeCreateServiceImpl codeCreateService;

   @Autowired
   SatCustomerFollowDubboService satCustomerFollowDubboServiceImpl;

   @Autowired
   SatCustomerClueDubboService satCustomerClueDubboServiceImpl;

   @Autowired
   @Reference(version = "1.0.0")
   CustomerDubboService customerDubboServiceImpl;

   @Autowired
   AreaManagerDubboService areaManagerDubboServiceImpl;

   @Autowired
   AreaDubboService areaDubboServiceImpl;

   @Autowired
   UrmDubboService urmDubboServiceImplBiz;

   @Autowired
   AppDubboService appDubboServiceImpl;

   @Value("${center.switch}")
   private String is2Center;

   @Value("${urm.switch}")
   private String is2URM;

   @Value("${app.switch}")
   private String is2App;

   @Autowired
   SatMessDubboService satMessDubboServiceImpl;

   @Autowired
   SatMessService satMessServiceImpl;

   @Autowired
   MsgTemplateDubboService msgTemplateDubboServiceImpl;

   @Autowired
   StaffDubboService staffDubboServiceBiz;

   @Autowired
   ActivitiManageDubboService activitiManageDubboService;

   @Autowired
   @Qualifier(value = "trRefundServiceImpl")
   TrRefundService trRefundService;

   @Autowired
   StoStockInPlanDubboService StoStockInPlanDubboServiceImpl;

   @Autowired
   AttachDubboService attachDubboServiceImpl;

   @Autowired
   PartnerDubboService partnerDubboServiceImpl;

   @Autowired
   CustomCreditReportingDubboService customCreditReportingDubboServiceBase;

    @Autowired
    Dict2BizDubboService dict2BizDubboService;

   @Autowired
   @Qualifier(value = "satMessServiceImpl")
   SatMessService satMessService;

   @Autowired
   @Qualifier(value = "handleVehicleServiceImpl")
   HandleVehicleService handleVehicleService;

   private static final Logger logger = LoggerFactory.getLogger(OrderCustomerDubboServiceImpl.class);
//
   @Override
   public OrderCustomerVO getById(String id) throws InvocationTargetException, IllegalAccessException {
      OrderCustomer orderCustomer = orderCustomerService.getById(id);
      OrderCustomerVO orderCustomerVO = new OrderCustomerVO();
      BeanUtils.copyProperties(orderCustomer, orderCustomerVO);
      return orderCustomerVO;
   }

   @Override
   @Transactional
   public ApiResult receiveApp(com.yunxi.hubToBiz.pojo.OrderCustomerVO appOrderCustomerVO) throws Exception {
      if (StringUtils.isNotEmpty(appOrderCustomerVO.getCustomerMobile())){
         if (appOrderCustomerVO.getCustomerMobile().length()!=11) return ResponseUtil.fail(-1,"手机号错误:"+appOrderCustomerVO.getCustomerMobile());
      }
      if (appOrderCustomerVO==null) return ResponseUtil.fail(-1,"请求参数为空");
      if (StringUtils.isEmpty(appOrderCustomerVO.getCustomerId())) return ResponseUtil.fail(-1,"用户的aiid:customerId:为空");
      if(StringUtils.isEmpty(appOrderCustomerVO.getOrderNo())) return ResponseUtil.fail(-1,"订单流水号:orderNo:为空");
      if (StringUtils.isEmpty(appOrderCustomerVO.getProductTypeCode())) return ResponseUtil.fail(-1,"车型编号:productTypeCode:为空");
      if (StringUtils.isEmpty(appOrderCustomerVO.getColorCode())) return ResponseUtil.fail(-1,"整车颜色编号:colorCode:为空");
      if (StringUtils.isEmpty(appOrderCustomerVO.getInteriorCode())) return ResponseUtil.fail(-1,"内饰编号:interiorCode:为空");
      if (appOrderCustomerVO.getBuyType()==null) return ResponseUtil.fail(-1,"购车方案:buyType:为空");
      if (appOrderCustomerVO.getOrderStatus()==null) return ResponseUtil.fail(-1,"订单状态:orderStatus:为空");
      if (appOrderCustomerVO.getOrderStatus().intValue() != 1 && appOrderCustomerVO.getOrderStatus().intValue() != 2 && appOrderCustomerVO.getOrderStatus().intValue() != 3) return ResponseUtil.fail(-1,"订单状态错误:orderStatus:"+appOrderCustomerVO.getOrderStatus());
      if (appOrderCustomerVO.getOrderStatus().intValue()==2) {
         if (appOrderCustomerVO.getBlAmount()==null || appOrderCustomerVO.getBlAmount().compareTo(new BigDecimal(0))==0 )
         return ResponseUtil.fail(-1,"订单状态"+appOrderCustomerVO.getOrderStatus()+"小订定金不能为空");
      }
      if (appOrderCustomerVO.getOrderStatus().intValue()==3) {
         if (appOrderCustomerVO.getBfAmount()==null || appOrderCustomerVO.getBfAmount().compareTo(new BigDecimal(0))==0)
         return ResponseUtil.fail(-1,"订单状态"+appOrderCustomerVO.getOrderStatus()+"大订定金不能为空");
      }
      if (StringUtils.isNotEmpty(appOrderCustomerVO.getPartnerCode())){
         List<PartnerVO> partnerVOS = partnerDubboServiceImpl.listByProductAuth(appOrderCustomerVO.getPartnerCode(),appOrderCustomerVO.getProductTypeCode());
         if (partnerVOS==null || partnerVOS.size()<=0) return ResponseUtil.fail(-1,"该渠道商:"+appOrderCustomerVO.getPartnerCode()+",不存在该产品授权:"+appOrderCustomerVO.getProductTypeCode());
      }

      QueryWrapper<OrderCustomer> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("ORDER_CUSTOMER_NO", appOrderCustomerVO.getOrderNo());
      int count = orderCustomerService.count(queryWrapper);
      OrderCustomerVO orderCustomerVO = new OrderCustomerVO();
      if (count == 0) {
         //新增
         setOrderCustomerVO(appOrderCustomerVO, orderCustomerVO);
         orderCustomerVO.setOrderSource(1);//订单来源App
         LoginInfo loginInfo = new LoginInfo();
         loginInfo.setUserCode("app接收新增");
         loginInfo.setRoleCode("app");
         if (StringUtils.isNotEmpty(appOrderCustomerVO.getFellowId()) ){
            List<String> list =  areaManagerDubboServiceImpl.getAreaManagerUserCodeByCityManagerUserCode(appOrderCustomerVO.getFellowId());
            if (list!=null && list.size()>1) return ResponseUtil.fail(-1,"该小区经理归属于多个大区经理:"+appOrderCustomerVO.getFellowId());
            String bigRegion =  areaManagerDubboServiceImpl.getBigRegionCodeByCityManagerUserCode(appOrderCustomerVO.getFellowId());
            if (StringUtils.isEmpty(bigRegion)) return ResponseUtil.fail(-1,"该城市辅导经理未配置所属大区经理:"+appOrderCustomerVO.getFellowId());
            orderCustomerVO.setBigRegion(bigRegion);
         } else if (StringUtils.isNotEmpty(appOrderCustomerVO.getCityCode()) ){
            String bigRegion = areaDubboServiceImpl.getBigRegionByCityCode(appOrderCustomerVO.getCityCode());
            orderCustomerVO.setBigRegion(bigRegion);
         }else {
            return ResponseUtil.fail(-1,"客户经理id或提车城市为空");
         }
         ApiResult result = this.save(orderCustomerVO, loginInfo);

         //judge this order buytype is hire type
         if(orderCustomerVO.getBuyType()==DMSEnumsEntity.OrderCustomerBuyType.HIRE.getCode()){
            //match vip order_vehicle
            //orderVehicleService.matchVipOrder(orderCustomerVO);

         }


         if (result.getCode()!=200){
            return result;
         }
      }
      else if (count == 1) {
         //修改
         OrderCustomerVO vo = orderCustomerService.load(appOrderCustomerVO.getOrderNo());
         setOrderCustomerVO(appOrderCustomerVO, orderCustomerVO);
         LoginInfo loginInfo = new LoginInfo();
         loginInfo.setUserCode("app接收修改");
         orderCustomerVO.setOrderCustomerId(vo.getOrderCustomerId());
         orderCustomerVO.getOrderCustomerDetailVO().setOrderCustomerDetailId(vo.getOrderCustomerDetailVO().getOrderCustomerDetailId());

         ApiResult apiResult = this.update(orderCustomerVO, loginInfo);
         if (apiResult.getCode()!=200){
            return apiResult;
         }
      }
      return ResponseUtil.ok();

   }

   private void setOrderCustomerVO(com.yunxi.hubToBiz.pojo.OrderCustomerVO appOrderCustomerVO, OrderCustomerVO orderCustomerVO) {
      orderCustomerVO.setCustomerId(appOrderCustomerVO.getCustomerId());//用户的aiid
      orderCustomerVO.setCustomerNo(appOrderCustomerVO.getCustomerId());//用户的aiid
      orderCustomerVO.setCustomerName(appOrderCustomerVO.getCustomerName());//用户姓名
      orderCustomerVO.setCustomerMobile(appOrderCustomerVO.getCustomerMobile());//用户手机号
      orderCustomerVO.setCertNo(appOrderCustomerVO.getCertNo());//用户证件号
      orderCustomerVO.setCompanyName(appOrderCustomerVO.getCompanyName());//下订单的企业名称
      orderCustomerVO.setCompanyCode(appOrderCustomerVO.getCompanyCode());//下订单的企业代码
      orderCustomerVO.setCityCode(appOrderCustomerVO.getCityCode());//提车城市
      if (StringUtils.isNotEmpty(appOrderCustomerVO.getCityCode())){
         AreaVO areaVO = new AreaVO();
         areaVO.setCode(appOrderCustomerVO.getCityCode());
         areaVO.setType(0);
         List<AreaVO> list = (List<AreaVO>) areaDubboServiceImpl.listByVo(areaVO, null);
         if (list!=null && list.size()>0){
            AreaVO vo = list.get(0);
            orderCustomerVO.setProvinceCode(vo.getPcode());
         }
      }



      orderCustomerVO.setInvitorName(appOrderCustomerVO.getInvitorName());//邀请人姓名
      orderCustomerVO.setInvitorMobile(appOrderCustomerVO.getInvitorMobile());//邀请人手机
      orderCustomerVO.setOrderStatus(appOrderCustomerVO.getOrderStatus());//订单状态
      orderCustomerVO.setOrderNo(appOrderCustomerVO.getOrderNo());//订单流水号
      orderCustomerVO.setOrderCustomerNo(appOrderCustomerVO.getOrderNo());//订单流水号
      orderCustomerVO.setTotalAmount(appOrderCustomerVO.getTotalAmount());//支付金额
      orderCustomerVO.setOutTradeNo(appOrderCustomerVO.getOutTradeNo());//支付流水号
      orderCustomerVO.setBuyType(appOrderCustomerVO.getBuyType());//购车方案 1-->购车 2-->体验车 3-->畅想车
      orderCustomerVO.setOrderSubject(appOrderCustomerVO.getOrderSubject());//订单名称
      orderCustomerVO.setOrderAmount(appOrderCustomerVO.getOrderAmount());//预估金额
      if (appOrderCustomerVO.getCertType() != null) {
         orderCustomerVO.setCertType(String.valueOf(appOrderCustomerVO.getCertType()));//证件类型 1->身份证
      }
      OrderCustomerDetailVO orderCustomerDetailVO = new OrderCustomerDetailVO();
      String productCode = appOrderCustomerVO.getProductTypeCode()+appOrderCustomerVO.getInteriorCode()+appOrderCustomerVO.getColorCode();
      ProductNameVO productNameVO = orderCustomerService.getNameByVO(productCode);
      orderCustomerDetailVO.setOrderNo(appOrderCustomerVO.getOrderNo());
      orderCustomerDetailVO.setOrderCustomerNo(appOrderCustomerVO.getOrderNo());

      // 后台对选装包排序
      StringBuilder sortCustomPackCode = new StringBuilder();
      if (!org.springframework.util.StringUtils.isEmpty(appOrderCustomerVO.getFeatureCode())) {
         // 对选装包进行分组字符串排序再组装
         String[] customPackCodes = appOrderCustomerVO.getFeatureCode().split(",");
         Arrays.sort(customPackCodes);
         for (String code : customPackCodes) {
            sortCustomPackCode.append(code).append(",");
         }
         sortCustomPackCode = new StringBuilder(sortCustomPackCode.substring(0, sortCustomPackCode.length() - 1));
      }else {
         sortCustomPackCode = null;
      }
      String finalCustomPackCode = sortCustomPackCode == null ? null : sortCustomPackCode.toString();
      orderCustomerDetailVO.setCustomPackCode(finalCustomPackCode);//选装包编号（逗号分隔）
      orderCustomerDetailVO.setVehicleCode(appOrderCustomerVO.getProductTypeCode());//车型编号
      orderCustomerDetailVO.setVehicleName(productNameVO.getVehicleName());
      orderCustomerVO.setProductPackageId(appOrderCustomerVO.getProductTypeCode());
      orderCustomerDetailVO.setColorCodeOut(appOrderCustomerVO.getColorCode());//整车颜色编号
      orderCustomerDetailVO.setColorNameOut(productNameVO.getColorNameOut());//外饰名称
      orderCustomerDetailVO.setHubCode(appOrderCustomerVO.getHubCode());//轮毂编号
      orderCustomerDetailVO.setBatteryPackCode(appOrderCustomerVO.getBatteryPackCode());//B包编号

      orderCustomerVO.setStateSubsidy(appOrderCustomerVO.getStateSubsidy());//国家补贴
      orderCustomerVO.setLocalSubsidy(appOrderCustomerVO.getLocalSubsidy());//地方补贴
      orderCustomerVO.setSmallAmount(appOrderCustomerVO.getBlAmount());//小订定金
      orderCustomerVO.setBigAmount(appOrderCustomerVO.getBfAmount());//大订定金
      orderCustomerVO.setFellowId(appOrderCustomerVO.getFellowId());//客户经理id
      orderCustomerVO.setFellowName(appOrderCustomerVO.getFellowName());//客户经理姓名
      orderCustomerVO.setFellowMobile(appOrderCustomerVO.getFellowMobile());//客户经理手机号
      orderCustomerVO.setFellowGender(appOrderCustomerVO.getFellowGender());//客户经理性别
      orderCustomerVO.setFellowAvatar(appOrderCustomerVO.getFellowAvatar());//客户经理头像url

      orderCustomerDetailVO.setColorCodeIn(appOrderCustomerVO.getInteriorCode());//内饰编号
      orderCustomerDetailVO.setColorNameIn(productNameVO.getColorNameIn());//内饰名称
      orderCustomerVO.setEnergyPoint(appOrderCustomerVO.getEnergyPoint());//能量值
      if (StringUtils.isEmpty(appOrderCustomerVO.getPartnerCode())){
         orderCustomerVO.setPartnerCode(null);//渠道商CODE
      }else {
         OrderCustomerVO vo = orderCustomerService.getByOrderCustomerNo(appOrderCustomerVO.getOrderNo());
         if (vo!=null && StringUtils.isNotEmpty(vo.getPartnerCode())){
            orderCustomerVO.setPartnerCode(vo.getPartnerCode());
         }else {
            orderCustomerVO.setPartnerCode(appOrderCustomerVO.getPartnerCode());
         }
      }
      orderCustomerVO.setVehicleStatus(appOrderCustomerVO.getVehicleStatus());//车辆状态
      orderCustomerVO.setCustomerAddress(appOrderCustomerVO.getCustomerAddress());//客户地址
      orderCustomerVO.setOrderCustomerDetailVO(orderCustomerDetailVO);
   }

   @Override
   @Transactional
   public ApiResult updateByListVo(List<OrderCustomerVO> orderCustomerVOList) throws IllegalAccessException, InvocationTargetException, InstantiationException {
      if (orderCustomerVOList == null || orderCustomerVOList.size() <= 0) return ResponseUtil.fail(-1,"请求参数为空");
      for (OrderCustomerVO orderCustomerVO : orderCustomerVOList) {
         if (!BeanTools.isAllFieldNull(orderCustomerVO)) {
            //将订单状态修改传入中台
            if ("true".equals(is2Center)) {
               OrderStatusReqDto orderStatusReqDto = new OrderStatusReqDto();
               //orderStatusReqDto.setAuditStatus();//审核状态
               ApiResult apiResult = pms2CenterUpdateStatus(orderCustomerVO, orderStatusReqDto);
               if (apiResult!=null) return apiResult;
            }
            if ("true".equals(is2URM)) {
               //将零售订单基本信息传入URM
               OrderInformationTransmissionVO orderInformationTransmissionVO = setOrderInforURM(orderCustomerVO);
               ApiResult apiResult = sendOrderInfo2URM(orderInformationTransmissionVO);
               if (apiResult.getCode() != 200) {
                  return apiResult;
               }
            }
         }
      }
      orderCustomerService.updateByListVo(orderCustomerVOList);
      return ResponseUtil.ok();
   }

   @Override
   @Transactional
   public ApiResult save(OrderCustomerVO orderCustomerVO, LoginInfo loginInfo) throws Exception {
      if (orderCustomerVO == null || BeanTools.isAllFieldNull(orderCustomerVO)) return ResponseUtil.fail(-1,"参数为空");
      //零售订单基本信息
      if (StringUtils.isEmpty(orderCustomerVO.getOrderCustomerId()) && StringUtils.isEmpty(orderCustomerVO.getOrderNo())) {
         ///orderCustomerVO.setCustomerId(GUIDGenerator.getPrimaryKey());//客户id
         if (StringUtils.isEmpty(orderCustomerVO.getOrderCustomerNo())) {
            orderCustomerVO.setOrderNo(codeCreateService.createCode("BB", "yyyyMMdd", 6));
            orderCustomerVO.setOrderCustomerNo(orderCustomerVO.getOrderNo());
         }
      }

      String orderNo = orderCustomerVO.getOrderNo();
      orderCustomerVO.setCreateBy(loginInfo.getUserCode());
      if (loginInfo.getPartner()!=null){
         orderCustomerVO.setSalesConsultantNo(loginInfo.getUserCode());
      }
      if (orderCustomerVO.getSmallAmount() != null) {
         if (orderCustomerVO.getOrderStatus()==null){
            orderCustomerVO.setOrderStatus(2);//大定已付款
         }
         orderCustomerVO.setBusType(0);//业务类型0 小订 1 大订
      }
      if (orderCustomerVO.getBigAmount() != null) {
         if (orderCustomerVO.getOrderStatus()==null){
            orderCustomerVO.setOrderStatus(3);//大定已付款
         }
         orderCustomerVO.setBusType(1);//业务类型0 小订 1 大订
         //生成默认交车人
         LoginInfo login = new LoginInfo();
         if (StringUtils.isNotEmpty(orderCustomerVO.getPartnerCode())){
            login.setPartnerCode(orderCustomerVO.getPartnerCode());
            ApiResult apiResult = staffDubboServiceBiz.listStaffByRoleCode("rolePartnerHandleVehicle", login);
            List<StaffVO> list = null;
            if (apiResult.getData() != null) {
               list = (List<StaffVO>) apiResult.getData();
            }
            if (list != null && list.size() > 0) {
               orderCustomerVO.setHandleUser(list.get(0).getAccountNo());
            } else {
               return ResponseUtil.fail(-1, "-------大定已付款,该渠道商没有交车专员,无法生成交车信息--------");
            }
         }
      }


//      if (StringUtils.isNotEmpty(orderCustomerVO.getPartnerCode())){
//         //同步客户信息
//         syncCustomer(orderCustomerVO, loginInfo);
//         //生成消息提醒
//         sendMsg(loginInfo, orderCustomerVO, "3", 3,"rolePartnerSale");
//      }else{
      //如果app推送订单的 渠道商code 为空 生成订单类型线索


      //1,partner code为空,则小区经理来进行分配线索
      //2,partner code不为空,则说明订单已绑定渠道商,此时有两种情况
      //2.1 客户在店里不存在,销售顾问抢单,只需要更新状态为已分配未领取,且更新partner code
      //2.2 客户在店里已经存在,则需从客户信息中获取销售顾问,并将线索置为已分配已领取,领取的顾问填充
      //已分配状态是根据partnercode不为空来进行判断的
      generateClue(orderCustomerVO);
//      }



      if ("true".equals(is2URM)) {
         //将零售订单基本信息传入URM
         OrderInformationTransmissionVO orderInformationTransmissionVO = setOrderInforURM(orderCustomerVO);
         ApiResult apiResult = sendOrderInfo2URM(orderInformationTransmissionVO);
         if (apiResult.getCode()!=200) return apiResult;
      }

      OrderCustomer orderCustomer = new OrderCustomer();
      BeanUtils.copyProperties(orderCustomerVO, orderCustomer);
      orderCustomer.setIsUpload("0");
      orderCustomerService.save(orderCustomer);

      if (orderCustomerVO.getBigAmount() != null && StringUtils.isNotEmpty(orderCustomerVO.getPartnerCode())) {
         try {
            //大定已付款 生成交车信息
            satCustomerFollowDubboServiceImpl.orderCustomerFollow(orderCustomer.getOrderCustomerId(), orderCustomerVO.getDeliveryCarDate(), true, true,loginInfo);
         } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            logger.error(" -------更新客户级别====跟进记录失败---------  ");
            return ResponseUtil.fail(-1, "更新客户级别====跟进记录失败");
         }
      }

      //零售订单车辆,内饰,外饰,选装包 信息
      OrderCustomerDetailVO orderCustomerDetailVO = orderCustomerVO.getOrderCustomerDetailVO();
      if (orderCustomerDetailVO != null) {
         if (StringUtils.isEmpty(orderCustomerDetailVO.getVehicleCode()) || StringUtils.isEmpty(orderCustomerDetailVO.getColorCodeIn()) || StringUtils.isEmpty(orderCustomerDetailVO.getColorCodeOut())) {
            return ResponseUtil.fail(-1, "请填写车辆信息,内外饰");
         }
         orderCustomerDetailVO.setOrderCustomerDetailId(UUID.randomUUID().toString().replaceAll("-", ""));
         orderCustomerDetailVO.setCustomerNo(orderCustomerVO.getCustomerId());
         orderCustomerDetailVO.setOrderNo(orderNo);
         orderCustomerDetailVO.setOrderCustomerNo(orderNo);
         orderCustomerDetailVO.setVehicleCode(orderCustomerVO.getProductPackageId() + "");
         orderCustomerDetailVO.setProductCode(orderCustomerDetailVO.getVehicleCode() + orderCustomerDetailVO.getColorCodeIn() + orderCustomerDetailVO.getColorCodeOut());
         if (StringUtils.isNotEmpty(orderCustomerDetailVO.getCustomPackCode())){
            String customPackName = orderCustomerService.findCustomPackName(orderCustomerDetailVO.getCustomPackCode());
            if (StringUtils.isNotEmpty(customPackName)) {
               String[] customPackNameArr = customPackName.split(";");
               String jsonString = JSON.toJSONString(customPackNameArr);
               orderCustomerDetailVO.setCustomPackName(jsonString);
            }
         }
         //将零售订单基本信息传入中台
         if ("true".equals(is2Center)) {
            OrderReqDto orderReqDto = setCenterOrderCustomer(orderCustomerVO);
            List<OrderDetailReqDto> orderDetailReqDtos = new ArrayList<>();
            OrderDetailReqDto orderDetailReqDto = setCenterOrderCustomerDetail(orderCustomerDetailVO);
            orderDetailReqDtos.add(orderDetailReqDto);
            orderReqDto.setOrderDetailReqDtos(orderDetailReqDtos);
            orderReqDto.setCreatePerson(loginInfo.getRealName());
            ApiResult apiResult = pms2CenterAdd(orderReqDto);
            if (apiResult!=null) return apiResult;
         }
         //将零售订单详情信息传入中台
//         if ("true".equals(is2Center)) {
//            if (orderCustomerVO.getEnergyPoint() != null) {
//               orderDetailReqDto.setEnergyPoint(Long.valueOf(orderCustomerVO.getEnergyPoint()));
//            }
//            orderDetailReqDto.setCreatePerson(loginInfo.getRealName());
//            ApiResult apiResult = pms2CenterAddDetail(orderDetailReqDto);
//            if (apiResult!=null) return apiResult;
//         }
         OrderCustomerDetailVO ocd = orderCustomerDetailDubboServiceImpl.getByOrderNo(orderCustomerDetailVO.getOrderNo());
         if(ocd!=null){
            orderCustomerDetailVO.setOrderCustomerDetailId(ocd.getOrderCustomerDetailId());
            orderCustomerDetailDubboServiceImpl.update(orderCustomerDetailVO);
         }else{
            orderCustomerDetailDubboServiceImpl.save(orderCustomerDetailVO);
         }
      }

      //零售订单附加信息
      List<OrderCustomerFeatureVO> orderCustomerFeatureVOList = orderCustomerVO.getOrderCustomerFeatureVOList();
      if (orderCustomerFeatureVOList != null && orderCustomerFeatureVOList.size() > 0) {
         for (OrderCustomerFeatureVO orderCustomerFeatureVO : orderCustomerFeatureVOList) {
            if (!StringUtils.isEmpty(orderCustomerFeatureVO.getFeatureName()) && !BeanTools.isAllFieldNull(orderCustomerFeatureVO)) {
               orderCustomerFeatureVO.setOrderCustomerFeatureId(UUID.randomUUID().toString().replaceAll("-", ""));
               orderCustomerFeatureVO.setOrderNo(orderNo);
               //将零售订单附加信息传入中台
               if ("true".equals(is2Center)) {
                  OrderAttributeReqDto orderAttributeReqDto = setCenterOrderCustomerAttr(orderCustomerFeatureVO);
                  orderAttributeReqDto.setCreatePerson(loginInfo.getRealName());
                  ApiResult apiResult = pms2CenterAddAttr(orderAttributeReqDto);
                  if (apiResult!=null) return apiResult;
               }
               orderCustomerFeatureDubboServiceImpl.save(orderCustomerFeatureVO);
            }
         }
      }

      return ResponseUtil.ok();
   }

   private void generateClue(OrderCustomerVO orderCustomerVO) throws Exception {
      SatCustomerClueVO satCustomerClueVO = new SatCustomerClueVO();
      satCustomerClueVO.setIsGet(0);//未领取 默认
      satCustomerClueVO.setPartnerCode(orderCustomerVO.getPartnerCode());
      satCustomerClueVO.setGetUser("");//领取人
      satCustomerClueVO.setAssignUser("");//分配人
      satCustomerClueVO.setLevel("1");//默认O级别
      if (StringUtils.isNotEmpty(orderCustomerVO.getPartnerCode())) {
         satCustomerClueVO.setPartnerCode(orderCustomerVO.getPartnerCode());
         satCustomerClueVO.setAssignUser("");//分配人
         satCustomerClueVO.setAssignDate(new Date());//分配时间
         CustomerVO customerVO = customerDubboServiceImpl.getByPhone(orderCustomerVO.getCustomerMobile(), orderCustomerVO.getPartnerCode());
         if (customerVO != null) {//客户不为空
            if (customerVO.getSalesConsultantNo() != null) {//已绑定销售顾问
               satCustomerClueVO.setIsGet(1);//已领取
               satCustomerClueVO.setGetUser(customerVO.getSalesConsultantNo());//领取人
               satCustomerClueVO.setGetDate(new Date());//领取时间
            }
         }
      }
      String code = codeCreateService.createCode("LS", "yyyyMMdd", 4);
      satCustomerClueVO.setClueNo(code);
      satCustomerClueVO.setClueType("3");
      satCustomerClueVO.setCustomerNo(orderCustomerVO.getCustomerNo());
      satCustomerClueVO.setCustomerName(orderCustomerVO.getCustomerName());
      satCustomerClueVO.setVehicleCode(orderCustomerVO.getProductPackageId());
      OrderCustomerDetailVO detailVO = orderCustomerVO.getOrderCustomerDetailVO();
      satCustomerClueVO.setColorInCode(detailVO.getColorCodeIn());
      satCustomerClueVO.setColorInName(detailVO.getColorNameIn());
      satCustomerClueVO.setColorOutCode(detailVO.getColorCodeOut());
      satCustomerClueVO.setColorOutName(detailVO.getColorNameOut());
      satCustomerClueVO.setTel(orderCustomerVO.getCustomerMobile());
      satCustomerClueVO.setUserCode("");
      satCustomerClueVO.setCreateTime(new Date());
      satCustomerClueVO.setCreateBy("app");
      satCustomerClueVO.setStatus(1);
      satCustomerClueVO.setProvince(orderCustomerVO.getProvinceCode());
      satCustomerClueVO.setCity(orderCustomerVO.getCityCode());
      satCustomerClueVO.setRegion(orderCustomerVO.getRegionCode());
      satCustomerClueVO.setCatalogName("");
      satCustomerClueVO.setSalesConsultantNo("");
      satCustomerClueVO.setClueSource("app");
      satCustomerClueVO.setItmcComeWay("");
      satCustomerClueVO.setItmcInDate("");
      satCustomerClueVO.setItmcOutDate("");
      satCustomerClueVO.setItmcAdviserCode("");
      satCustomerClueVO.setSalAdviserCode("");
      satCustomerClueVO.setSex("");
      satCustomerClueVO.setSeries("");
      satCustomerClueVO.setIntentModel("");
      satCustomerClueVO.setGetInfoWay("");
      satCustomerClueVO.setCreateTimeStr("");
      satCustomerClueVO.setGetDateStr("");
      satCustomerClueVO.setUserName("");
      satCustomerClueVO.setBigRegionManager("");
      satCustomerClueVO.setIsRemind(0);
      satCustomerClueVO.setPcode(orderCustomerVO.getBigRegion());
      satCustomerClueVO.setBusinessKey(orderCustomerVO.getOrderCustomerNo());

      satCustomerClueDubboServiceImpl.saveOrUpdate(satCustomerClueVO);
   }

   private ApiResult sendOrderInfo2URM(OrderInformationTransmissionVO orderInformationTransmissionVO) {
      ApiResult apiResult = null;
      try {
         apiResult = urmDubboServiceImplBiz.sendOrderInformationTransmissionPMS2Urm(orderInformationTransmissionVO);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" -------URM调用出错 _ pmsOrderInfo2URM __< 将零售订单基本信息传入URM  >-" + e.getMessage());
         e.printStackTrace();
         return ResponseUtil.fail(-1,"URM调用出错:"+ e.getMessage());
      }
      if (200 != apiResult.getCode()) {
         logger.error("URM接口执行，将零售订单基本信息传入URM失败，事务回滚!");
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         return ResponseUtil.fail(-1,"URM接口执行,将零售订单基本信息传入URM失败:"+ apiResult.getMsg());
      }
      return apiResult;
   }

   private OrderInformationTransmissionVO setOrderInforURM(OrderCustomerVO orderCustomerVO) {
      OrderInformationTransmissionVO orderInformationTransmissionVO = new OrderInformationTransmissionVO();
      orderInformationTransmissionVO.setParnterNo(orderCustomerVO.getPartnerCode());//渠道商代码
      orderInformationTransmissionVO.setAIID(orderCustomerVO.getCustomerId());//用户的aiid
      if (orderCustomerVO.getOrderSource() != null) {
         orderInformationTransmissionVO.setOrderSource("1");//订单来源
      }
      if (orderCustomerVO.getIsCancel() != null) {
         orderInformationTransmissionVO.setIsCancel(String.valueOf(orderCustomerVO.getIsCancel()));//是否退订
      }

      orderInformationTransmissionVO.setCancelReason(orderCustomerVO.getCancelReason());//退订原因
      if (orderCustomerVO.getCancelAudit() != null) {
         orderInformationTransmissionVO.setCancelAudit(String.valueOf(orderCustomerVO.getCancelAudit()));//退订是否审核
      }
      if (orderCustomerVO.getCancelDate() != null) {
         orderInformationTransmissionVO.setCancelDate(new SimpleDateFormat("yyyyMMdd").format(orderCustomerVO.getCancelDate()));//取消时间
      }
      if (orderCustomerVO.getSmallAmount() != null) {
         orderInformationTransmissionVO.setSmallAmount(String.valueOf(orderCustomerVO.getSmallAmount()));//小订金额
      }
      if (orderCustomerVO.getSmallPayDate() != null) {
         orderInformationTransmissionVO.setSmallPayDate(new SimpleDateFormat("yyyyMMdd").format(orderCustomerVO.getSmallPayDate()));//小订付款时间
      }
      if (orderCustomerVO.getSmallPayPath() != null) {
         orderInformationTransmissionVO.setSmallPayPath(String.valueOf(orderCustomerVO.getSmallPayPath()));//付款途径
      }
      if (orderCustomerVO.getBigAmount() != null) {
         orderInformationTransmissionVO.setBigAmount(String.valueOf(orderCustomerVO.getBigAmount()));//大订金额
      }
      if (orderCustomerVO.getBigPayPath() != null) {
         orderInformationTransmissionVO.setBigPayDate(new SimpleDateFormat("yyyyMMdd").format(orderCustomerVO.getBigPayPath()));//大订时间
      }
      return orderInformationTransmissionVO;
   }

   @Deprecated //Guan 2020-01-08
   private void syncCustomer(OrderCustomerVO orderCustomerVO, LoginInfo loginInfo) throws Exception {

      if (StringUtils.isEmpty(loginInfo.getPartnerCode())) {
         loginInfo.setPartnerCode(orderCustomerVO.getPartnerCode());
      }
      CustomerVO v1 = customerDubboServiceImpl.getByPhone(orderCustomerVO.getCustomerMobile(), loginInfo.getPartnerCode());
      if (v1 != null) {
         v1.setCustomerNo(orderCustomerVO.getCustomerNo());
         v1.setName(orderCustomerVO.getCustomerName());
         v1.setTelephone(orderCustomerVO.getCustomerMobile());
         v1.setPhone(orderCustomerVO.getCustomerMobile());
      } else {
         //本地创建 并上传到URM
         v1 = new CustomerVO();
         v1.setName(orderCustomerVO.getCustomerName());
         v1.setTelephone(orderCustomerVO.getCustomerMobile());
         v1.setPhone(orderCustomerVO.getCustomerMobile());
         v1.setCustStatus(1); //0意向 1订单 2战败 3基盘 4线索
         v1.setPartnerCode(orderCustomerVO.getPartnerCode());


      }
      ApiResult apiResult = customerDubboServiceImpl.saveOrUpdate(v1, loginInfo);
      if (apiResult.getCode()==200){
         if(apiResult.getData()!=null){
            String ordercustomerNoURM = (String) apiResult.getData();
            orderCustomerVO.setCustomerId(ordercustomerNoURM);
            orderCustomerVO.setCustomerNo(ordercustomerNoURM);
         }
      }
   }


   private OrderDetailReqDto setCenterOrderCustomerDetail(OrderCustomerDetailVO orderCustomerDetailVO) {
      OrderDetailReqDto orderDetailReqDto = new OrderDetailReqDto();
      orderDetailReqDto.setOrderDetailId(orderCustomerDetailVO.getOrderCustomerDetailId());//订单明细ID
      orderDetailReqDto.setOrderId(orderCustomerDetailVO.getOrderNo());//订单ID
      orderDetailReqDto.setProductCode(orderCustomerDetailVO.getProductCode());//商品编码
      orderDetailReqDto.setVehicleCode(orderCustomerDetailVO.getVehicleCode());//型谱15位码
      //orderDetailReqDto.setVehicleSeries();//车系
      //orderDetailReqDto.setVehicleModel();//车型
      //orderDetailReqDto.setVehicleLevel();//车配置
      orderDetailReqDto.setColorOutCode(orderCustomerDetailVO.getColorCodeOut());//外观颜色编码
      orderDetailReqDto.setColorOutName(orderCustomerDetailVO.getColorNameOut());//外观颜色名称
      orderDetailReqDto.setColorInCode(orderCustomerDetailVO.getColorCodeIn());//内饰颜色编码
      orderDetailReqDto.setColorInName(orderCustomerDetailVO.getColorNameIn());//内饰颜色名称
      //电池包编码
      //电池包名称
      orderDetailReqDto.setCustomPackCode(orderCustomerDetailVO.getCustomPackCode());//选装包编码
      orderDetailReqDto.setCustomPackName(orderCustomerDetailVO.getCustomPackName());//选装包名称
      orderDetailReqDto.setHubCode(orderCustomerDetailVO.getHubCode());//轮毂编号
      return orderDetailReqDto;
   }

   private OrderReqDto setCenterOrderCustomer(OrderCustomerVO orderCustomerVO) {
      OrderReqDto orderReqDto = new OrderReqDto();
      orderReqDto.setOrderId(orderCustomerVO.getOrderNo());//订单ID
      orderReqDto.setOrderSubject(orderCustomerVO.getOrderSubject());//订单名称
      orderReqDto.setMemberId(orderCustomerVO.getCustomerId());//会员ID
      orderReqDto.setMemberName(orderCustomerVO.getCustomerName());//会员名称
      orderReqDto.setMemberMobile(orderCustomerVO.getCustomerMobile());//会员手机号
      orderReqDto.setMemberType(orderCustomerVO.getCustomerType());//会员类型
      if (StringUtils.isNotEmpty(orderCustomerVO.getCertType())) {
         orderReqDto.setCertType(Integer.valueOf(orderCustomerVO.getCertType()));//证件类型
      }

      orderReqDto.setCertNo(orderCustomerVO.getCertNo());//证件号
      orderReqDto.setBusType(orderCustomerVO.getBusType());//业务类型 0：小订 1 ：大定
      Integer i = StringUtils.isEmpty(orderCustomerVO.getBookingType()) ? null : Integer.valueOf(orderCustomerVO.getBookingType());
      orderReqDto.setBookingType(i);//1：个人2：企业
      orderReqDto.setBusType(orderCustomerVO.getBuyType());//购车方案 "1-->购车 2-->体验车 3-->畅想车
      orderReqDto.setCompanyCode(orderCustomerVO.getCompanyCode());//企业编号
      orderReqDto.setCompanyName(orderCustomerVO.getCompanyName());//企业名称
      orderReqDto.setChannelCode(orderCustomerVO.getPartnerCode());//渠道商编号
      orderReqDto.setChannelName(orderCustomerVO.getPartnerName());//渠道商名称
      orderReqDto.setAdvisorId(orderCustomerVO.getSalesConsultantNo());//销售顾问id
      orderReqDto.setAdvisorName("");//销售顾问名称
      orderReqDto.setOrderSource(orderCustomerVO.getOrderSource());//订单来源 1：App， 2：CP，3：后台录入
      orderReqDto.setOrderType(orderCustomerVO.getOrderType());//订单类型 1：零售整车 2：值客整车
      orderReqDto.setOrderStatus(orderCustomerVO.getOrderStatus());//订单状态
      orderReqDto.setOptout(orderCustomerVO.getIsCancel());//是否退订 1：未退订 2：已退订
//      orderReqDto.setOptoutType(); //退订方式 1：客户取消 2：超时取消 3：退款 4：退货
//      orderReqDto.setOptoutTime(); //退订时间
      orderReqDto.setOptoutReason(orderCustomerVO.getCancelReason()); //退订原因
      if (orderCustomerVO.getTotalAmount() != null) {
         orderReqDto.setTotalAmt(orderCustomerVO.getTotalAmount().doubleValue());//订单总金额
      }
      if (orderCustomerVO.getDiscountAmount() != null) {
         orderReqDto.setCouponAmt(new Double(String.valueOf(orderCustomerVO.getDiscountAmount())));//优惠金额
      }
      if (orderCustomerVO.getStateSubsidy() != null) {
         orderReqDto.setStateSubsidy(Double.valueOf((orderCustomerVO.getStateSubsidy().toString())));//国家补贴
      }
      if (orderCustomerVO.getLocalSubsidy() != null) {
         orderReqDto.setLocalSubsidy(Double.valueOf((orderCustomerVO.getLocalSubsidy().toString())));//地方补贴
      }
      if (orderCustomerVO.getSmallAmount() != null) {
         orderReqDto.setSmallAmt(new Double(String.valueOf(orderCustomerVO.getSmallAmount())));//小订金额
      }
      if (orderCustomerVO.getSmallPayPath() != null) {
         orderReqDto.setSmallPayWay(String.valueOf(orderCustomerVO.getSmallPayPath()));//小订付款方式
      }
      orderReqDto.setSmallPayTime(orderCustomerVO.getSmallPayDate());//小订付款时间
      if (orderCustomerVO.getBigAmount() != null) {
         orderReqDto.setBigAmt(new Double(String.valueOf(orderCustomerVO.getBigAmount())));//大定金额
      }
      if (orderCustomerVO.getBigPayPath() != null) {
         orderReqDto.setBigPayWay(String.valueOf(orderCustomerVO.getBigPayPath()));//大定付款方式
      }
      orderReqDto.setBigPayTime(orderCustomerVO.getBigPayDate());//大定付款时间
      if (orderCustomerVO.getFinalAmount() != null) {
         orderReqDto.setFinalAmt(new Double(String.valueOf(orderCustomerVO.getFinalAmount())));//尾款金额
      }
      if (orderCustomerVO.getFinalPayPath() != null) {
         orderReqDto.setFinalPayWay(String.valueOf(orderCustomerVO.getFinalPayPath()));//尾款方式
      }
      orderReqDto.setFinalPayTime(orderCustomerVO.getFinalDate()); //尾款时间
      orderReqDto.setDeliveryPlanTime(orderCustomerVO.getDeliveryCarDate());//预计交车日期
//      orderReqDto.setDeliveryCarTime();//交车日期
      orderReqDto.setInvitorName(orderCustomerVO.getInvitorName());//邀请人姓名
      orderReqDto.setInvitorMobile(orderCustomerVO.getInvitorMobile());//邀请人手机号
      orderReqDto.setFellowId(orderCustomerVO.getFellowId());//客户经理id
      orderReqDto.setFellowName(orderCustomerVO.getFellowName());//客户经理姓名
      orderReqDto.setFellowMobile(orderCustomerVO.getFellowMobile());//客户经理手机号
      if (StringUtils.isNotEmpty(orderCustomerVO.getFellowGender())) {
         orderReqDto.setFellowGender(Integer.valueOf(orderCustomerVO.getFellowGender()));//客户经理1-男，2-女
      }
      orderReqDto.setFellowAvatar(orderCustomerVO.getFellowAvatar());//客户经理头像url
      Integer str = StringUtils.isEmpty(orderCustomerVO.getDeliveryType()) ? null : Integer.parseInt(orderCustomerVO.getDeliveryType());
      orderReqDto.setDeliveryType(str);//提货方式 1:自提 2：直送
      orderReqDto.setTakeCarName(orderCustomerVO.getTakeCarName());//提车人姓名
      orderReqDto.setTakeCarTel(orderCustomerVO.getTakeCarTel());//提车人电话
      orderReqDto.setContractCode(orderCustomerVO.getContractNo());//合同编号
      orderReqDto.setInvoiceCode(orderCustomerVO.getInvoiceCode());//发票编号
      if (orderCustomerVO.getInvoiceMoney() != null) {
         orderReqDto.setInvoiceMoney(new Double(String.valueOf(orderCustomerVO.getInvoiceMoney())));//开票金额
      }
      orderReqDto.setInvoiceTime(orderCustomerVO.getInvoiceTime());//开票时间
      orderReqDto.setInsuranceNo(orderCustomerVO.getInsuranceNo());//保单号
      orderReqDto.setInsurer(orderCustomerVO.getInsurerType());//保险公司
      orderReqDto.setDrivierName(orderCustomerVO.getDriverName());//车主姓名
      orderReqDto.setDrivierTel(orderCustomerVO.getDriverTel());//车主电话
      orderReqDto.setDrivierType(orderCustomerVO.getDrivierType());//车主类型
      orderReqDto.setLicenseTime(orderCustomerVO.getCarLicense());//车牌日期
      orderReqDto.setCarNo(orderCustomerVO.getCarNo());//车牌号
      orderReqDto.setVin(orderCustomerVO.getVin());//VIN
      orderReqDto.setProductPackage(orderCustomerVO.getProductPackageId());//预定的产品包
      orderReqDto.setLowStocks(orderCustomerVO.getIsLowStock());//n:库存不足；y:库存充足，默认n
      orderReqDto.setCarNum(orderCustomerVO.getNum());//数量
      orderReqDto.setIsCharging(orderCustomerVO.getIsChargingPoint());//是否安装充电桩 0否1是
      orderReqDto.setVehicleStatus(orderCustomerVO.getVehicleStatus());//车辆状态
      orderReqDto.setProvince(orderCustomerVO.getProvinceCode());//省
//      orderReqDto.setProvinceName();//省名称
      orderReqDto.setCity(orderCustomerVO.getCityCode());//市
      //orderReqDto.setCityName(orderCustomerVO.get);//市名称
//      orderReqDto.setCounty();//区
//      orderReqDto.setCountyName();//区名称
      orderReqDto.setAddress(orderCustomerVO.getCustomerAddress());//地址

      return orderReqDto;
   }


   private OrderAttributeReqDto setCenterOrderCustomerAttr(OrderCustomerFeatureVO orderCustomerFeatureVO) {
      OrderAttributeReqDto orderAttributeReqDto = new OrderAttributeReqDto();
      orderAttributeReqDto.setOrderId(orderCustomerFeatureVO.getOrderNo());//订单ID
//      orderAttributeReqDto.setAttrCode(orderCustomerFeatureVO.getFeatureCode());//属性代码
      orderAttributeReqDto.setAttrCode(GUIDGenerator.getPrimaryKey());//属性代码
      orderAttributeReqDto.setAttrName(orderCustomerFeatureVO.getFeatureName());//属性名称
      orderAttributeReqDto.setAttrType(orderCustomerFeatureVO.getFeatureType());//属性类型
      if (orderCustomerFeatureVO.getAmount() != null) {
         orderAttributeReqDto.setAllAmt(new Double(orderCustomerFeatureVO.getAmount().toString()));//总金额
      }
      if (orderCustomerFeatureVO.getPrice() != null) {
         orderAttributeReqDto.setPrice(new Double(orderCustomerFeatureVO.getPrice().toString()));//单价
      }
      orderAttributeReqDto.setAttrConut(orderCustomerFeatureVO.getNum());//数量
      orderAttributeReqDto.setSettleType(orderCustomerFeatureVO.getBalanceType());//结算方式
//               orderAttributeReqDto.setExtField1();
//               orderAttributeReqDto.setExtField2();
//               orderAttributeReqDto.setExtField3();
//               orderAttributeReqDto.setExtField4();
      return orderAttributeReqDto;
   }

   private String getChinesses(String str){
      if (StringUtils.isEmpty(str)) return null;
      String regex="([\u4e00-\u9fa5]+)";
      Matcher matcher = Pattern.compile(regex).matcher(str);
      if(matcher.find()){
         return matcher.group(0);
      }
      return null;
   }

   private ApiResult pms2CenterAdd(OrderReqDto orderReqDto) {
      RestResponse<Long> longRestResponse = null;
      try {
         //将渠道信息传入中台
         longRestResponse = orderApi.addOrder(orderReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错 _ pms2CenterAdd __< 新增零售订单基本信息  >-" + e.getMessage());
         e.printStackTrace();
         if (this.getChinesses(e.getMessage())!=null){
            return ResponseUtil.fail(-1,"中台调用出错__pms2CenterAdd___<新增零售订单基本信息>__" + this.getChinesses(e.getMessage()));
         }
         return ResponseUtil.fail(-1,"中台调用出错:"+ e.getMessage());
      }
      if (!longRestResponse.getResultCode().equals("0")) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台执行失败 _ pms2CenterAdd __< 新增零售订单基本信息  >-" + longRestResponse.getResultMsg());
         return ResponseUtil.fail(-1,"中台执行失败" + longRestResponse.getResultMsg());
      }
      return null;
   }

   private ApiResult pms2CenterUpdate(OrderReqDto orderReqDto, String outTradeNo) {
      RestResponse<Void> voidRestResponse = null;
      try {
         //将渠道信息传入中台
         String orderId = orderReqDto.getOrderId();
         voidRestResponse = orderApi.updateOrder(orderId, outTradeNo, orderReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错 _ pms2CenterUpdate __< 修改零售订单基本信息  >-" + e.getMessage());
         e.printStackTrace();
         if (this.getChinesses(e.getMessage())!=null){
            return ResponseUtil.fail(-1,"中台调用出错___<修改零售订单基本信息>-" + this.getChinesses(e.getMessage()));
         }
         return ResponseUtil.fail(-1,"中台调用出错:"+ e.getMessage());
      }
      if (!voidRestResponse.getResultCode().equals("0")) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台执行失败 _ pms2CenterUpdate __< 修改零售订单基本信息  >-" + voidRestResponse.getResultMsg());
         return ResponseUtil.fail(-1,"中台执行失败:"+ voidRestResponse.getResultMsg());
      }
      return null;
   }

   private ApiResult pms2CenterAddDetail(OrderDetailReqDto orderDetailReqDto) {
      RestResponse<Long> longRestResponse = null;
      try {
         //将渠道信息传入中台
         longRestResponse = orderApi.addOrderDetail(orderDetailReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错 _ pms2CenterAddDetail __< 新增零售订单详情信息  >-" + e.getMessage());
         e.printStackTrace();
         if (this.getChinesses(e.getMessage())!=null){
            return ResponseUtil.fail(-1,"中台调用出错___<新增零售订单详情信息>-" + this.getChinesses(e.getMessage()));
         }
         return ResponseUtil.fail(-1,"中台调用出错:"+ e.getMessage());
      }
      if (!longRestResponse.getResultCode().equals("0")) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台执行失败 _ pms2CenterAddDetail __< 新增零售订单详情信息  >-" + longRestResponse.getResultMsg());
         return ResponseUtil.fail(-1,"中台执行失败:"+ longRestResponse.getResultMsg());
      }
      return null;
   }

   private ApiResult pms2CenterUpdateDetail(OrderDetailReqDto orderDetailReqDto) {
      RestResponse<Void> voidRestResponse = null;
      try {
         //将渠道信息传入中台
         voidRestResponse = orderApi.updateOrderDetail(orderDetailReqDto.getOrderDetailId(), orderDetailReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错 _ pms2CenterUpdateDetail __< 修改零售订单详情信息  >-" + e.getMessage());
         e.printStackTrace();
         if (this.getChinesses(e.getMessage())!=null){
            return ResponseUtil.fail(-1,"中台调用出错___<修改零售订单详情信息>-" + this.getChinesses(e.getMessage()));
         }
         return ResponseUtil.fail(-1,"中台调用出错:"+ e.getMessage());
      }
      if (!voidRestResponse.getResultCode().equals("0")) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台执行失败 _ pms2CenterUpdateDetail __< 修改零售订单详情信息  >-" + voidRestResponse.getResultMsg());
         return ResponseUtil.fail(-1,"中台执行失败:"+ voidRestResponse.getResultMsg());
      }
      return null;
   }

   private ApiResult pms2CenterAddAttr(OrderAttributeReqDto orderAttributeReqDto) {
      RestResponse<Long> longRestResponse = null;
      try {
         //将渠道信息传入中台
         longRestResponse = orderApi.addOrderAttribute(orderAttributeReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错 _ pms2CenterUpdateDetail __< 新增零售订单附加信息  >-" + e.getMessage());
         e.printStackTrace();
         if (this.getChinesses(e.getMessage())!=null){
            return ResponseUtil.fail(-1,"中台调用出错___<新增零售订单附加信息>-" + this.getChinesses(e.getMessage()));
         }
         return ResponseUtil.fail(-1,"中台调用出错:"+ e.getMessage());
      }
      if (!longRestResponse.getResultCode().equals("0")) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台执行失败 _ pms2CenterUpdateDetail __< 新增零售订单附加信息  >-" + longRestResponse.getResultMsg());
         return ResponseUtil.fail(-1,"中台执行失败:"+ longRestResponse.getResultMsg());
      }
      return null;
   }

   private ApiResult pms2CenterUpdateAttr(OrderAttributeReqDto orderAttributeReqDto) {
      RestResponse<Void> voidRestResponse = null;
      try {
         //将渠道信息传入中台
         voidRestResponse = orderApi.updateOrderAttribute(orderAttributeReqDto.getOrderId(), orderAttributeReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错 _ pms2CenterUpdateAttr __< 修改零售订单附加信息  >-" + e.getMessage());
         e.printStackTrace();
         if (this.getChinesses(e.getMessage())!=null){
            return ResponseUtil.fail(-1,"中台调用出错___<修改零售订单附加信息>-" + this.getChinesses(e.getMessage()));
         }
         return ResponseUtil.fail(-1,"中台调用出错:"+ e.getMessage());
      }
      if (!voidRestResponse.getResultCode().equals("0")) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台执行失败 _ pms2CenterUpdateAttr __< 修改零售订单附加信息  >-" + voidRestResponse.getResultMsg());
         return ResponseUtil.fail(-1,"中台执行失败:"+ voidRestResponse.getResultMsg());
      }
      return null;
   }

   private ApiResult pms2CenterUpdateStatus(OrderCustomerVO orderCustomerVO, OrderStatusReqDto orderStatusReqDto) {
      RestResponse<Void> voidRestResponse = null;
      try {
         //将渠道信息传入中台
         voidRestResponse = orderApi.refundStatus(orderCustomerVO.getOrderNo(), orderCustomerVO.getOutTradeNo(), orderCustomerVO.getStatus(), orderStatusReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错 _ pms2CenterUpdateStatus __< 修改零售订单状态  >-" + e.getMessage());
         e.printStackTrace();
         if (this.getChinesses(e.getMessage())!=null){
            return ResponseUtil.fail(-1,"中台调用出错___<修改零售订单状态>-" + this.getChinesses(e.getMessage()));
         }
         return ResponseUtil.fail(-1,"中台调用出错:"+ e.getMessage());
      }
      if (!voidRestResponse.getResultCode().equals("0")) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台执行失败 _ pms2CenterUpdateStatus __< 修改零售订单状态  >-" + voidRestResponse.getResultMsg());
         return ResponseUtil.fail(-1,"中台执行失败:"+ voidRestResponse.getResultMsg());
      }
      return null;
   }

   @Override
   @Transactional
   public ApiResult update(OrderCustomerVO orderCustomerVO, LoginInfo loginInfo) throws IllegalAccessException {
      if (orderCustomerVO == null || BeanTools.isAllFieldNull(orderCustomerVO)) return ResponseUtil.fail(-1,"数据为空");
      if (StringUtils.isNotEmpty(orderCustomerVO.getOrderNo())){
         orderCustomerVO.setOrderCustomerNo(orderCustomerVO.getOrderNo());
      }else if (StringUtils.isNotEmpty(orderCustomerVO.getOrderCustomerNo())){
         orderCustomerVO.setOrderNo(orderCustomerVO.getOrderCustomerNo());
      }
      String orderNo = orderCustomerVO.getOrderNo();
      orderCustomerVO.setUpdateBy(loginInfo.getUserCode());
      QueryWrapper<OrderCustomer> wrapper = new QueryWrapper<>();
      wrapper.eq("ORDER_CUSTOMER_NO", orderNo);
      OrderCustomer one = orderCustomerService.getOne(wrapper);
      if (one==null) return ResponseUtil.fail(-1,"不存在改订单"+orderNo);
      if (one.getOrderStatus().intValue()==7 || one.getOrderStatus().intValue()==10) return ResponseUtil.fail(-1,"该订单已申请退订,无法修改");
      if ("1".equals(one.getIsUpload())) return ResponseUtil.fail(-1,"该订单已上传合同照片,无法修改");

      if (orderCustomerVO.getSmallAmount() != null && one.getIsCancel().intValue()==0) {
         orderCustomerVO.setOrderStatus(2);//小订付款完成
         orderCustomerVO.setBusType(0);//业务类型0 小订 1 大订
      }

      if (orderCustomerVO.getBigAmount() != null && one.getIsCancel().intValue()==0) {
         orderCustomerVO.setOrderStatus(3);//大订已付款
         orderCustomerVO.setBusType(1);//业务类型0 小订 1 大订
      }

      if (orderCustomerVO.getBigAmount() != null) {
         //生成交车人
         if (StringUtils.isEmpty(one.getHandleUser()) && StringUtils.isNotEmpty(orderCustomerVO.getPartnerCode())) {
            LoginInfo login = new LoginInfo();
            login.setPartnerCode(orderCustomerVO.getPartnerCode());
            ApiResult apiResult = staffDubboServiceBiz.listStaffByRoleCode("rolePartnerHandleVehicle", login);
            List<StaffVO> list = null;
            if (apiResult.getData() != null) {
               list = (List<StaffVO>) apiResult.getData();
            }
            if (list != null && list.size() > 0) {
               orderCustomerVO.setHandleUser(list.get(0).getAccountNo());
            } else {
               return ResponseUtil.fail(-1, "-------大定已付款,该渠道商没有交车专员,无法生成交车信息--------");
            }

            try {
               //生成交车信息
               satCustomerFollowDubboServiceImpl.orderCustomerFollow(one.getOrderCustomerId(), orderCustomerVO.getDeliveryCarDate(), false, true,loginInfo);
            } catch (Exception e) {
               TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
               e.printStackTrace();
               logger.error(" -------更新客户级别====跟进记录失败---------  ");
               return ResponseUtil.fail(-1, "更新客户级别====跟进记录失败");
            }
         }
      }

      //将零售订单基本信息传入中台
      if ("true".equals(is2Center)) {
         OrderReqDto orderReqDto = setCenterOrderCustomer(orderCustomerVO);
         orderReqDto.setUpdatePerson(loginInfo.getRealName());
         ApiResult apiResult = pms2CenterUpdate(orderReqDto, GUIDGenerator.getPrimaryKey());
         if (apiResult!=null) return apiResult;
      }
      if ("true".equals(is2URM)) {
         //将零售订单基本信息传入URM
         OrderInformationTransmissionVO orderInformationTransmissionVO = setOrderInforURM(orderCustomerVO);
         ApiResult apiResult = sendOrderInfo2URM(orderInformationTransmissionVO);
         if (apiResult.getCode()!=200) return apiResult;
      }

      OrderCustomer orderCustomer = new OrderCustomer();
      BeanUtils.copyProperties(orderCustomerVO, orderCustomer);
      orderCustomer.setUpdateBy(loginInfo.getUserCode());
      QueryWrapper<OrderCustomer> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("ORDER_CUSTOMER_NO", orderNo);


      //零售订单车辆,内饰,外饰,选装包 信息
      OrderCustomerDetailVO orderCustomerDetailVO = orderCustomerVO.getOrderCustomerDetailVO();
      if (orderCustomerDetailVO != null && !BeanTools.isAllFieldNull(orderCustomerDetailVO)) {
         if (!StringUtils.isEmpty(orderCustomerDetailVO.getVehicleCode())) {
            //新增detail Guan 有问题 需要通过 零售订单号判断 之前 明细数据是否存在
            if (StringUtils.isEmpty(orderCustomerDetailVO.getOrderCustomerDetailId())) {
               orderCustomerDetailVO.setOrderCustomerDetailId(UUID.randomUUID().toString().replaceAll("-", ""));
               orderCustomerDetailVO.setOrderNo(orderNo);
               orderCustomerDetailVO.setCreateBy(loginInfo.getUserCode());
               orderCustomerDetailVO.setProductCode(orderCustomerDetailVO.getVehicleCode() + orderCustomerDetailVO.getColorCodeIn() + orderCustomerDetailVO.getColorCodeOut());
               //将零售订单详情信息传入中台
               if ("true".equals(is2Center)) {
                  OrderDetailReqDto orderDetailReqDto = setCenterOrderCustomerDetail(orderCustomerDetailVO);
                  if (orderCustomerVO.getEnergyPoint() != null) {
                     orderDetailReqDto.setEnergyPoint(Long.valueOf(orderCustomerVO.getEnergyPoint()));
                  }
                  orderDetailReqDto.setCreatePerson(loginInfo.getRealName());
                  ApiResult apiResult = pms2CenterAddDetail(orderDetailReqDto);
                  if (apiResult!=null) return apiResult;
               }
               orderCustomerDetailDubboServiceImpl.save(orderCustomerDetailVO);
            } else {
               //修改detail
               //将零售订单详情信息传入中台
               if (StringUtils.isNotEmpty(orderCustomerDetailVO.getCustomPackCode())){
                  String customPackName = orderCustomerService.findCustomPackName(orderCustomerDetailVO.getCustomPackCode());
                  if (StringUtils.isNotEmpty(customPackName)) {
                     String[] customPackNameArr = customPackName.split(";");
                     String jsonString = JSON.toJSONString(customPackNameArr);
                     orderCustomerDetailVO.setCustomPackName(jsonString);
                  }
               }else {
                  orderCustomerDetailVO.setCustomPackCode("");
                  orderCustomerDetailVO.setCustomPackName("");
               }
               orderCustomerDetailVO.setProductCode(orderCustomerDetailVO.getVehicleCode() + orderCustomerDetailVO.getColorCodeIn() + orderCustomerDetailVO.getColorCodeOut());
               orderCustomerDetailVO.setUpdateBy(loginInfo.getUserCode());
               if ("true".equals(is2Center)) {
                  OrderDetailReqDto orderDetailReqDto = setCenterOrderCustomerDetail(orderCustomerDetailVO);
                  if (orderCustomerVO.getEnergyPoint() != null) {
                     orderDetailReqDto.setEnergyPoint(Long.valueOf(orderCustomerVO.getEnergyPoint()));
                  }
                  orderDetailReqDto.setUpdatePerson(loginInfo.getRealName());
                  ApiResult apiResult = pms2CenterUpdateDetail(orderDetailReqDto);
                  if (apiResult!=null) return apiResult;
               }
               orderCustomerDetailDubboServiceImpl.update(orderCustomerDetailVO);
            }
         }
      }


      List<OrderCustomerFeatureVO> orderCustomerFeatureVOList = orderCustomerVO.getOrderCustomerFeatureVOList();
      if (orderCustomerFeatureVOList != null && orderCustomerFeatureVOList.size() > 0) {
         for (OrderCustomerFeatureVO orderCustomerFeatureVO : orderCustomerFeatureVOList) {
            if (!StringUtils.isEmpty(orderCustomerFeatureVO.getFeatureName())) {
               //新增零售订单附加信息
               if (StringUtils.isEmpty(orderCustomerFeatureVO.getOrderCustomerFeatureId())) {
                  orderCustomerFeatureVO.setOrderCustomerFeatureId(UUID.randomUUID().toString().replaceAll("-", ""));
                  orderCustomerFeatureVO.setOrderNo(orderNo);
                  orderCustomerFeatureVO.setCreateBy(loginInfo.getUserCode());
                  //将零售订单附加信息传入中台
                  if ("true".equals(is2Center)) {
                     OrderAttributeReqDto orderAttributeReqDto = setCenterOrderCustomerAttr(orderCustomerFeatureVO);
                     orderAttributeReqDto.setCreatePerson(loginInfo.getRealName());
                     ApiResult apiResult = pms2CenterAddAttr(orderAttributeReqDto);
                     if (apiResult!=null) return apiResult;
                  }
                  orderCustomerFeatureDubboServiceImpl.save(orderCustomerFeatureVO);
               } else {
                  //修改零售订单附加信息
                  //将零售订单附加信息传入中台
                  if ("true".equals(is2Center)) {
                     OrderAttributeReqDto orderAttributeReqDto = setCenterOrderCustomerAttr(orderCustomerFeatureVO);
                     orderAttributeReqDto.setUpdatePerson(loginInfo.getRealName());
                     ApiResult apiResult = pms2CenterUpdateAttr(orderAttributeReqDto);
                     if (apiResult!=null) return apiResult;
                  }
                  orderCustomerFeatureVO.setUpdateBy(loginInfo.getUserCode());
                  orderCustomerFeatureDubboServiceImpl.update(orderCustomerFeatureVO);
               }
            }
         }
      }

      //订单合同图片
      if ("1".equals(orderCustomerVO.getIsPmsOp())){
         if (orderCustomerVO.getAttachVOList() != null && orderCustomerVO.getAttachVOList().size() > 0) {
            List<CustomCreditReportingVO> list = customCreditReportingDubboServiceBase.getByOrderCustomerNo(orderCustomerVO.getOrderCustomerNo());
            if (list!=null && list.size()>0){
               CustomCreditReportingVO customCreditReportingVO = list.get(0);
               if (one.getBuyType()==2){
                  if (customCreditReportingVO.getApprovalStatus().intValue() !=2) return ResponseUtil.fail(-1,"当前体验车订单用户征信尚未审核通过,无法上传合同照片");
               }else if (one.getBuyType()==1){
                  if (customCreditReportingVO.getApprovalStatus().intValue() !=5) return ResponseUtil.fail(-1,"当前订单金融方案用户尚未确认,无法上传合同照片");
               }
            }else {
               if (one.getBuyType()==2) return ResponseUtil.fail(-1,"当前体验车订单尚未上传征信信息,无法上传合同照片");
            }
            attachDubboServiceImpl.saveByAttachVoList(orderCustomerVO.getAttachVOList(), "pms_order_customer", orderCustomerVO.getOrderCustomerNo(), loginInfo);
            orderCustomer.setIsUpload("1");
            ApiResult result = this.sendOrderStatus2App(orderCustomerVO, "OC01_OD_1000","1002");
            if (result!=null) return result;
         }else {
            attachDubboServiceImpl.delByBusSubId("pms_order_customer",orderCustomerVO.getOrderCustomerNo());
            orderCustomer.setIsUpload("0");
         }
      }
      orderCustomerService.update(orderCustomer, queryWrapper);

      if (orderCustomerVO.getDeliveryCarDate()!=null){
         ApiResult result = this.sendOrderStatus2App(orderCustomerVO, "OC01_OD_2000", "1003");
         if (result!=null) return result;
      }

      //同步更新线索,客户信息
      updateRelatedInfo(orderCustomerVO);

      return ResponseUtil.ok();
   }

   @Override
   public ApiResult sendOrderStatus2App(OrderCustomerVO orderCustomerVO,String rpname,String stCode) {
      OrderStatusVO orderStatusVO = new OrderStatusVO();
      orderStatusVO.setZzvin(orderCustomerVO.getVin());
      orderStatusVO.setRpname(rpname);
      orderStatusVO.setZpassd(DateUtil.format(new Date()));
      orderStatusVO.setStCode(stCode);
      if (orderCustomerVO.getOrderStatus()!=null){
         if (orderCustomerVO.getOrderStatus()==3){
            orderStatusVO.setOrderStatus("2");
         }
      }

      orderStatusVO.setOrderNo(orderCustomerVO.getOrderCustomerNo());
      orderStatusVO.setZobl1("");
      orderStatusVO.setZobl2("");
      orderStatusVO.setZobl3("");
      ApiResult result = appDubboServiceImpl.sendOrderStatusPMS2APP(orderStatusVO);
      if (result.getCode()!=200){
         logger.error("app执行失败，更新订单车辆状态失败，事务回滚!"+result.getMsg());
         return ResponseUtil.fail(-1,"app执行失败，更新订单车辆状态失败!"+result.getMsg());
      }
      return null;
   }

   private void updateRelatedInfo(OrderCustomerVO orderCustomerVO) {
      if (StringUtils.isNotEmpty(orderCustomerVO.getPartnerCode())){
         SatCustomerClueVO satCustomerClueVO = new SatCustomerClueVO();
         satCustomerClueVO.setPartnerCode(orderCustomerVO.getPartnerCode());
         satCustomerClueVO.setCustomerNo(orderCustomerVO.getCustomerId());
         satCustomerClueVO.setCustomerName(orderCustomerVO.getCustomerName());
         satCustomerClueVO.setVehicleCode(orderCustomerVO.getProductPackageId());
         satCustomerClueVO.setTel(orderCustomerVO.getCustomerMobile());
         satCustomerClueVO.setProvince(orderCustomerVO.getProvinceCode());
         satCustomerClueVO.setCity(orderCustomerVO.getCityCode());
         satCustomerClueVO.setRegion(orderCustomerVO.getRegionCode());
         satCustomerClueVO.setPcode(orderCustomerVO.getBigRegion());
         satCustomerClueVO.setBusinessKey(orderCustomerVO.getOrderCustomerNo());
         satCustomerClueDubboServiceImpl.updateByBusinessKey(satCustomerClueVO);

         CustomerVO customerVO = new CustomerVO();
         customerVO.setPartnerCode(orderCustomerVO.getPartnerCode());
         customerVO.setCustomerNo(orderCustomerVO.getCustomerId());
         customerVO.setName(orderCustomerVO.getCustomerName());
         customerVO.setPhone(orderCustomerVO.getCustomerMobile());
         customerVO.setTelephone(orderCustomerVO.getCustomerMobile());
         customerVO.setProvince(orderCustomerVO.getProvinceCode());
         customerVO.setCity(orderCustomerVO.getCityCode());
         customerVO.setVehicleCode(orderCustomerVO.getProductPackageId());
         customerDubboServiceImpl.updateByCustomerNo(customerVO);
      }
   }

   /**
    * 配车解绑 订货单中的零售订单号清空
    * @param orderCustomerVO
    * @param loginInfo
    * @return
    */
   @Override
   public ApiResult unbindCar(OrderCustomerVO orderCustomerVO, LoginInfo loginInfo) {
      QueryWrapper<OrderCustomer> wrapper = new QueryWrapper<>();
      wrapper.eq("ORDER_NO", orderCustomerVO.getOrderNo());
      OrderCustomer old = orderCustomerService.getOne(wrapper);

      if (old!=null && StringUtils.isNotEmpty(old.getCustomerId())){
         OrderCustomer orderCustomer = callBackCancel(old, loginInfo);
         orderCustomerService.unbindCar(orderCustomer);
      }
      return ResponseUtil.ok();
   }

   @Override
   @Transactional
   @Deprecated
   public ApiResult assignPartner(List<OrderCustomerVO> orderCustomerVOList, LoginInfo loginInfo) throws Exception {

      if (orderCustomerVOList!=null && orderCustomerVOList.size()>0){
         for (OrderCustomerVO orderCustomerVO : orderCustomerVOList) {
            orderCustomerVO.setUpdateBy(loginInfo.getUserCode());
            orderCustomerService.assignPartner(orderCustomerVO);

            OrderCustomer orderCustomer = orderCustomerService.getById(orderCustomerVO.getOrderCustomerId());
            LoginInfo login = new LoginInfo();
            if (orderCustomer.getBigAmount() != null) {
               //大定已付款,生成默认交车人
               if (StringUtils.isNotEmpty(orderCustomer.getPartnerCode())){
                  login.setPartnerCode(orderCustomer.getPartnerCode());
                  ApiResult apiResult = staffDubboServiceBiz.listStaffByRoleCode("rolePartnerHandleVehicle", login);
                  List<StaffVO> list = null;
                  if (apiResult.getData() != null) {
                     list = (List<StaffVO>) apiResult.getData();
                  }
                  if (list != null && list.size() > 0) {
                     orderCustomer.setHandleUser(list.get(0).getAccountNo());
                     orderCustomerService.saveOrUpdate(orderCustomer);
                  } else {
                     return ResponseUtil.fail(-1, "-------大定已付款,该渠道商没有交车专员,无法生成交车专员--------");
                  }

                  try {
                     //大定已付款 生成交车信息
                     satCustomerFollowDubboServiceImpl.orderCustomerFollow(orderCustomer.getOrderCustomerId(), orderCustomerVO.getDeliveryCarDate(), false, true,loginInfo);
                  } catch (Exception e) {
                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                     e.printStackTrace();
                     logger.error(" -------更新客户级别====跟进记录失败---------  ");
                     return ResponseUtil.fail(-1, "更新客户级别====跟进记录失败");
                  }
               }
            }
            if (StringUtils.isNotEmpty(orderCustomer.getPartnerCode())){
               //同步客户信息
               OrderCustomerVO vo = new OrderCustomerVO();
               BeanUtils.copyProperties(orderCustomer,vo);
               syncCustomer(vo, login);
//               //生成消息提醒
//               sendMsg(login, orderCustomerVO, "3", 3,"rolePartnerSale");
            }
         }
         return ResponseUtil.ok();
      }else {
         return ResponseUtil.fail(-1,"请选择渠道商");
      }
   }

   @Override
   @Transactional
   public void updateDeliveryInfo(OrderCustomerVO orderCustomerVO, LoginInfo loginInfo) throws Exception {

      QueryWrapper<OrderCustomer> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("ORDER_CUSTOMER_NO", orderCustomerVO.getOrderCustomerNo());
      OrderCustomer orderCustomer = new OrderCustomer();
      orderCustomer.setDeliveryCarDate(orderCustomerVO.getDeliveryCarDate());
      orderCustomer.setHandleUser(orderCustomerVO.getHandleUser());
      orderCustomerService.update(orderCustomer, queryWrapper);
      OrderCustomerVO ocVO = orderCustomerService.getByOrderCustomerNo(orderCustomerVO.getOrderCustomerNo());
      try {
         //生成交车信息
         LoginInfo info = new LoginInfo();
         info.setUserCode(orderCustomerVO.getHandleUser());
         satCustomerFollowDubboServiceImpl.orderCustomerFollow(ocVO.getOrderCustomerId(), orderCustomerVO.getDeliveryCarDate(), false, true,info);


         // 发送消息给交车专员
         SatMessAddVO satMessAddVO = new SatMessAddVO();
         satMessAddVO.setType("5");
         satMessAddVO.setTemplateType(21);
         satMessAddVO.setCustomerName(orderCustomerVO.getCustomerName());
         satMessAddVO.setCustomerNo(orderCustomerVO.getCustomerNo());
         satMessAddVO.setSalesConsultantNo(orderCustomerVO.getHandleUser());
         satMessAddVO.setReceiveRoleCode("rolePartnerHandleVehicle");
         satMessAddVO.setOperaRoleCode(loginInfo.getRoleCode());

         HandleVehicleVO hv = new HandleVehicleVO();
         hv.setOrderCustomerNo(orderCustomer.getOrderCustomerNo());
         List<HandleVehicleVO> list = handleVehicleService.listByVo(hv);
         if (!CollectionUtils.isEmpty(list)){
            satMessAddVO.setBusinessKey(list.get(0).getHandleId());
         }
         satMessService.newMess(satMessAddVO);
      } catch (Exception e) {
         e.printStackTrace();
         logger.error(" -------更新客户级别====跟进记录失败---------  ");
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         return ;
      }

      // 发送订单状态到APP
      ApiResult result = this.sendOrderStatus2App(ocVO, "OC01_OD_2000", "1003");
      if (result!=null) throw  new Exception(result.getMsg());
   }

   @Override
   public ApiResult receiveApp2(com.yunxi.hubToBiz.pojo.OrderCustomerVO appOrderCustomerVO) throws Exception {
      return receiveApp(appOrderCustomerVO);
   }

   @Override
   public PageInfo<OrderCustomerVO> cancelPageWait(OrderCustomerVO v, Integer pageNum,Integer pageSize, LoginInfo loginInfo) {
      return orderCustomerService.cancelPageWait(v,pageNum,pageSize,loginInfo);
   }

/**************************************************************************** APP对接业务
 * 1、由app发起退订
 * 2、pms回传审批结果
 * 3、app发送财务审批结果
 * 4、pms返回意见列表
 * 5、app发起取消，流程自动结束
 */
   /**
    * App退订申请 /财务审核结果 ->PMS
    * @param
    * @return
    * @throws InvocationTargetException
    * @throws IllegalAccessException
    */
   @Override
   @Transactional
   public ApiResult cancelApplyApp(CancelVOAPP cancelVOAPP) throws Exception {
      if (StringUtils.isEmpty( cancelVOAPP.getRefundOrderNo())) return ResponseUtil.fail(-1,"退款申请单号为空");
      if (cancelVOAPP.getRefundStatus()==null) return ResponseUtil.fail(-1,"退款标志为空");
      if (StringUtils.isEmpty(cancelVOAPP.getOrderNo())) return ResponseUtil.fail(-1,"退款订单号为空");

      ApiResult apiResult = null;
      /**  退款标志 0-> 申请中 1->已退款 2->退款失败 3->已取消 4财务拒绝 5 财务同意 */
      if(0==(cancelVOAPP.getRefundStatus().intValue()) ){/**  退订申请  */
         apiResult = cancelApply(cancelVOAPP);
      }else if (3==(cancelVOAPP.getRefundStatus().intValue())) {/**  退订取消  */
         apiResult = cancelApplyRemove(cancelVOAPP);
      }
      else if (4==(cancelVOAPP.getRefundStatus().intValue())){ /**  财务审核拒绝  */
         apiResult = cancelApplyFinanceRefuse(cancelVOAPP);
      }else if(5==(cancelVOAPP.getRefundStatus().intValue())){/**  财务审核同意  */
         apiResult = cancelApplyFinanceAgree(cancelVOAPP);//需要修改代码逻辑 Guan 2019-11-22
      }
      return apiResult;

   }

   private ApiResult cancelApplyRemove(CancelVOAPP cancelVOAPP) {

      /** 根据单号查询订单信息 */
      OrderCustomerVO vo = orderCustomerService.getByOrderCustomerNo(cancelVOAPP.getOrderNo());
      if (vo==null) return ResponseUtil.fail( -1,"没有该订单:"+cancelVOAPP.getOrderNo()+"");
      if (!vo.getRefundOrderNo().equals(cancelVOAPP.getRefundOrderNo())) return ResponseUtil.fail( -1,"退款取消:退款申请单号错误:"+cancelVOAPP.getOrderNo()+"");
      QueryWrapper<TrRefund> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("refund_no",cancelVOAPP.getRefundOrderNo());
      List<TrRefund> refundList = trRefundService.list(queryWrapper);
      if (refundList!=null && refundList.size()>0){
         TrRefund trRefund = refundList.get(0);
         if (trRefund.getStatus().intValue()==2) return ResponseUtil.fail(-1,"当前订单退订审核通过无法取消该退订申请");
         if (trRefund.getStatus().intValue()==3) return ResponseUtil.fail(-1,"当前订单退订审核驳回无法取消该退订申请");
         if (trRefund.getStatus().intValue()==0) return ResponseUtil.fail(-1,"当前订单尚未发起退订无法取消退订申请");
      }else {
         return ResponseUtil.fail(-1,"当前订单尚未发起退订");
      }

      ApiResult apiResult = activitiManageDubboService.stopActivitiByBusinessKey(vo.getOrderCustomerId());

      if (vo.getSmallAmount() != null) {
         vo.setOrderStatus(2);//小定已付款
      }
      if (vo.getBigAmount()!= null){
         vo.setOrderStatus(3);//大定已付款
      }
      vo.setCancelAudit(DMSEnumsEntity.OrderCancelStatus.NORMAL.getKey());
      vo.setIsCancel(0);
      vo.setCancelAudit(0);
      OrderCustomer one = new OrderCustomer();
      BeanUtils.copyProperties(vo,one);
      orderCustomerService.updateById(one);


      TrRefund trRefund = new TrRefund();
      trRefund.setStatus(0);
      trRefund.setIsCancel(1);
      trRefundService.update(trRefund,queryWrapper);

      //订单退订取消传入中台
      if ("true".equals(is2Center)){
         RefundReqDto refundReqDto = setRefundReqDto(vo);
         ApiResult result = pms2CenterCancelRefund(vo, refundReqDto);
         if (result!=null) return result;
      }

      return apiResult;
   }

   @Override
   public ApiResult loadByOrderCustomerNo(String orderCustomerNo) {
      QueryWrapper<OrderCustomer> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("ORDER_CUSTOMER_NO", orderCustomerNo);
      OrderCustomer one = orderCustomerService.getOne(queryWrapper);
      return ResponseUtil.ok(one);
   }

   @Override
   public OrderCustomerVO getByOrderCustomerNo(String orderCustomerNo) {
      QueryWrapper<OrderCustomer> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("ORDER_CUSTOMER_NO", orderCustomerNo);
      OrderCustomer one = orderCustomerService.getOne(queryWrapper);
      OrderCustomerVO vo = new OrderCustomerVO();
      if (one!=null){
         BeanUtils.copyProperties(one,vo);
      }
      return vo;
   }


   /**
    *
    * 退车
    * @param orderCustomerVO
    * @param loginInfo
    * @return
    */
   @Override
   @Transactional
   public ApiResult refundCar(OrderCustomerVO orderCustomerVO, LoginInfo loginInfo) throws Exception {
      QueryWrapper<OrderCustomer> wrapper = new QueryWrapper<>();
      wrapper.eq("ORDER_NO", orderCustomerVO.getOrderCustomerNo());
      OrderCustomer orderCustomer = orderCustomerService.getOne(wrapper);
      if(orderCustomer==null || StringUtils.isEmpty(orderCustomer.getOrderCustomerId())) return ResponseUtil.fail(-1,"没有找到该零售单:"+orderCustomerVO.getOrderCustomerNo());
      if (StringUtils.isEmpty(orderCustomer.getVin())) return ResponseUtil.fail(-1,"该零售订单尚未配车:"+orderCustomerVO.getOrderCustomerNo());
      if (StringUtils.isEmpty(orderCustomer.getPartnerCode())) return ResponseUtil.fail(-1,"该零售订单尚未分配渠道商:"+orderCustomerVO.getOrderCustomerNo());


      if (orderCustomer.getBuyType()!=null && orderCustomer.getBuyType()==1){
//车辆入库
         StoStockReturnInVO stoStockReturnInVO = new StoStockReturnInVO();
         stoStockReturnInVO.setVin(orderCustomer.getVin());
         stoStockReturnInVO.setPartnerCode(orderCustomer.getPartnerCode());
         StoStockInPlanDubboServiceImpl.returnIn(stoStockReturnInVO);

         //推送零售退车到APP
         vehiclePdiBillDubboService.sentMsgToApp(orderCustomer.getVin(),DictConstant.APP_RPNAME_VDC_SRETURN,DictConstant.APP_CODE_08);

         //调用中台退车接口
         if ("true".equals(is2Center)){
            ReturnReqDto returnReqDto = new ReturnReqDto();
            returnReqDto.setReturnNo(GUIDGenerator.getPrimaryKey());//退货单号
            returnReqDto.setOrderId(orderCustomer.getOrderCustomerNo());//订单ID
            returnReqDto.setChannelCode(orderCustomer.getPartnerCode());//渠道编码
            returnReqDto.setMemberId(orderCustomer.getCustomerNo());//会员ID
            returnReqDto.setStatus(1);//申请状态 1处理中，2已审核，3已发货，4已收货，5已验货，6已付款，0关闭
            returnReqDto.setReturnMethod(2);//退货方式 1.快递退回 2.自己退回网点
            returnReqDto.setReturnItemAmount(0.0D);//退货商品总金额
            returnReqDto.setReturnReason("");//退货原因
            returnReqDto.setRejectReason("");//拒绝原因
            returnReqDto.setReturnExplain("");//退货说明
            returnReqDto.setSendoutTime(new Date());//发货时间
            returnReqDto.setExamineTime(new Date());//审核时间
            returnReqDto.setReceiveTime(new Date());//收货时间
            returnReqDto.setExaminetTime(new Date());//检查时间
            returnReqDto.setCloseReason("");//关闭原因
            returnReqDto.setCloseTime(new Date());//关闭时间
            returnReqDto.setContactName(orderCustomer.getCustomerName());//联系人姓名
            returnReqDto.setContactPhone(orderCustomer.getCustomerMobile());//联系人手机
            returnReqDto.setExamineResult("");//验货结果1.正常退货，2.损坏退货
//      returnReqDto.setId(0L);
//      returnReqDto.setRemark("");
            returnReqDto.setCreatePerson(loginInfo.getUserCode());
//      returnReqDto.setUpdatePerson("");
//      returnReqDto.setExtFields(Maps.newHashMap());


//            if (!voidRestResponse.getResultCode().equals("0")) {
//               TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//               logger.error(" -------中台退车失败_refundCar__<退车>-" + voidRestResponse.getResultMsg());
//               return ResponseUtil.fail(-1,"中台执行失败:"+ voidRestResponse.getResultMsg());
//            }





            RestResponse<Void> voidRestResponse = null;
            try {
               //将渠道信息传入中台
               voidRestResponse = returnApi.applyReturn("TN" + GUIDGenerator.getPrimaryKey(), returnReqDto);//申请退车
            } catch (Exception e) {
               TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
               logger.error(" ------- 中台调用出错_refundCar__<申请退车>-" + e.getMessage());
               e.printStackTrace();
               if (this.getChinesses(e.getMessage())!=null){
                  return ResponseUtil.fail(-1,"中台调用出错___申请退车_:" + this.getChinesses(e.getMessage()));
               }
               return ResponseUtil.fail(-1,"中台调用出错___申请退车_:"+ e.getMessage());
            }
            if (!voidRestResponse.getResultCode().equals("0")) {
               TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
               logger.error(" ------- 中台执行失败 _ refundCar __<申请退车>-" + voidRestResponse.getResultMsg());
               return ResponseUtil.fail(-1,"中台执行失败,申请退车:"+ voidRestResponse.getResultMsg());
            }



//            RestResponse<Void> voidRestResponse1 = null;//退车审核
//            try {
//               //将渠道信息传入中台
//               voidRestResponse1 = returnApi.auditReturn("TN" + GUIDGenerator.getPrimaryKey(), returnReqDto);//申请退车
//            } catch (Exception e) {
//               TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//               logger.error(" ------- 中台调用出错_refundCar__<退车审核>-" + e.getMessage());
//               e.printStackTrace();
//               if (this.getChinesses(e.getMessage())!=null){
//                  return ResponseUtil.fail(-1,"中台调用出错___退车审核_:" + this.getChinesses(e.getMessage()));
//               }
//               return ResponseUtil.fail(-1,"中台调用出错___退车审核_:"+ e.getMessage());
//            }
//            if (!voidRestResponse1.getResultCode().equals("0")) {
//               TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//               logger.error(" ------- 中台执行失败 _refundCar__< 修改零售订单附加信息  >-" + voidRestResponse1.getResultMsg());
//               return ResponseUtil.fail(-1,"中台执行失败,退车审核:"+ voidRestResponse1.getResultMsg());
//            }
         }
      }

      //配车解绑 订货单中的零售订单号清空
      orderCustomerVO.setOrderNo(orderCustomerVO.getOrderCustomerNo());
      this.unbindCar(orderCustomerVO, loginInfo);

      return ResponseUtil.ok();
   }


   @Autowired
   OrderVehicleService orderVehicleServiceImpl;


   /**
    * 渠道商入库 更新零售订单vin 如果改vin对应的批售单绑定了零售单 将车辆锁定
    * @param vin
    * @return
    */
   @Override
   public void updateVin(String vin) throws InvocationTargetException, IllegalAccessException {
      QueryWrapper<OrderVehicle> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("VIN",vin);
      List<OrderVehicle> list = orderVehicleServiceImpl.list(queryWrapper);
      if (list!=null && list.size()>0){
         OrderVehicle orderVehicle = list.get(0);
         if (StringUtils.isNotEmpty(orderVehicle.getCustomOrderNo())){
            orderCustomerService.updateVin(vin);
            VehicleOfflineVO vo = vehicleOfflineDubboServiceImpl.getOne(queryWrapper);
            vo.setIsLock(1);//1绑定订单已配车
            OrderCustomerVO orderCustomerVO = orderCustomerService.getByOrderCustomerNo(orderVehicle.getCustomOrderNo());
            //体验次数+1
            if (orderCustomerVO.getBuyType()==2){
               Integer experienceCount = vo.getExperienceCount();
               vo.setExperienceCount(++experienceCount);
            }
            if (StringUtils.isNotEmpty(vo.getVehicleId())) {
               vehicleOfflineDubboServiceImpl.saveOrUpdate(vo);
            }
         }
      }
   }

   @Override
   public void updateByOrderCustomerNo(String orderCustomerNo) {
      orderCustomerService.updateByOrderCustomerNo(orderCustomerNo);
   }

   @Override
   public void hire(String orderCustomerNo, String vin) throws Exception {
      OrderCustomerVO ocv = orderCustomerService.getByOrderCustomerNo(orderCustomerNo);
      OrderCustomer oc = new OrderCustomer();
      BeanUtils.copyProperties(ocv,oc);
      oc.setVin(vin);
      oc.setHireStartDate(WgrDate.getCurrentDate());
      orderCustomerService.updateById(oc);

      VehicleStockBindVO vs = new VehicleStockBindVO();
      vs.setVin(vin);
      vs.setBindState(3);
      vehicleStockDubboService.vehicleBind(vs);
      vehiclePdiBillDubboService.sentMsgToApp(vin,orderCustomerNo,DictConstant.APP_RPNAME_VEHICLE_BIND,DictConstant.APP_CODE_09);
   }

   @Override
   public void revert(String vin) throws Exception {
      //订单表结束时间更新
      OrderCustomerVO ocv = orderCustomerService.getByVin(vin);
      OrderCustomer oc = new OrderCustomer();
      BeanUtils.copyProperties(ocv,oc);
      oc.setHireEndDate(WgrDate.getCurrentDate());
      orderCustomerService.updateById(oc);

      VehicleStockBindVO vs = new VehicleStockBindVO();
      vs.setVin(vin);
      vs.setBindState(1);
      vehicleStockDubboService.vehicleBind(vs);
      vehiclePdiBillDubboService.sentMsgToApp(vin,ocv.getOrderCustomerNo(),DictConstant.APP_RPNAME_VEHICLE_UNBIND,DictConstant.APP_CODE_10);
   }

   @Override
   public void cancel(String vin) throws Exception {
      OrderCustomerVO ocv = orderCustomerService.getByVin(vin);
      OrderCustomer oc = new OrderCustomer();
      BeanUtils.copyProperties(ocv,oc);
      orderCustomerService.cancel(oc);

      VehicleStockBindVO vs = new VehicleStockBindVO();
      vs.setVin(vin);
      vs.setBindState(1);
      vehicleStockDubboService.vehicleBind(vs);
   }

   /**
    * 财务审核结果 拒绝 ->PMS
    * @param cancelVOAPP
    * @return
    */
   private ApiResult cancelApplyFinanceRefuse(CancelVOAPP cancelVOAPP) throws InvocationTargetException, IllegalAccessException {

      /** 根据单号查询订单信息 */
      OrderCustomerVO vo = orderCustomerService.getByOrderCustomerNo(cancelVOAPP.getOrderNo());
      if (vo==null) return ResponseUtil.fail( -1,"没有该订单:"+cancelVOAPP.getOrderNo()+"");
      if (!vo.getRefundOrderNo().equals(cancelVOAPP.getRefundOrderNo())) return ResponseUtil.fail( -1,"财务审核拒绝:退款申请单号错误:"+cancelVOAPP.getOrderNo()+"");

      QueryWrapper<TrRefund> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("refund_no",cancelVOAPP.getRefundOrderNo());
      TrRefund trRefund = new TrRefund();
      trRefund.setStatus(3);
      trRefund.setIsCancel(1);
      trRefundService.update(trRefund,queryWrapper);

      LoginInfo loginInfo = new LoginInfo();
      loginInfo.setUserCode("财务");
      //
      ActivitiTaskVO task = activitiManageDubboService.getCurTaskIdByBusinessKey(vo.getOrderCustomerId());
      vo.setTaskStatus("AGREE");
      vo.setTaskId(task.getTaskId());
      vo.setInstanceId(task.getInstanceId());
      //查询流程实际情况，如果为财务驳回，无需执行退订业务，在流程结束时把意见发给app
      if(StringUtils.isNotEmpty(task.getTaskId())){
         System.out.println("财务退订驳回");
         activitiManageDubboService.next(vo.getInstanceId(),vo.getTaskId(),vo.getTaskStatus(),loginInfo);
      }
      //启动驳回流程
      if(StringUtils.isNotEmpty(vo.getPartnerCode())&&StringUtils.isNotEmpty(vo.getSalesConsultantNo())){
         return activitiManageDubboService.start("tuidingbohui",vo.getOrderCustomerId(),loginInfo);
      }else{
         //启动小区驳回流程
         return activitiManageDubboService.start("tuidingxiaoqubohui",vo.getOrderCustomerId(),loginInfo);
      }
   }

   /**
    * 财务审核结果 同意 ->PMS
    * @param cancelVOAPP
    * @return
    */
   private ApiResult cancelApplyFinanceAgree(CancelVOAPP cancelVOAPP) throws InvocationTargetException, IllegalAccessException {

      /** 根据单号查询订单信息 */
      OrderCustomerVO vo = orderCustomerService.getByOrderCustomerNo(cancelVOAPP.getOrderNo());
      if (vo==null) return ResponseUtil.fail( -1,"没有该订单:"+cancelVOAPP.getOrderNo()+"");
      if (!vo.getRefundOrderNo().equals(cancelVOAPP.getRefundOrderNo())) return ResponseUtil.fail( -1,"财务审核同意:退款申请单号错误:"+cancelVOAPP.getOrderNo()+"");

      QueryWrapper<TrRefund> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("refund_no",cancelVOAPP.getRefundOrderNo());
      TrRefund trRefund = new TrRefund();
      trRefund.setStatus(2);
      trRefund.setIsCancel(0);
      trRefundService.update(trRefund,queryWrapper);

      LoginInfo loginInfo = new LoginInfo();
      loginInfo.setUserCode("财务");
      loginInfo.setRoleCode("appCaiwu");
      //将流程结束，确认流程结束之后，需要执行 订单状态更新，发送app请求，发送中台请求
      ActivitiTaskVO task = activitiManageDubboService.getCurTaskIdByBusinessKey(vo.getOrderCustomerId());
      vo.setTaskStatus("AGREE");
      vo.setTaskId(task.getTaskId());
      vo.setInstanceId(task.getInstanceId());
      //查询流程实际情况，完成最后一个环节,同意后，需要把意见发给APP，退订审核业务需要执行
      if(task!=null&&StringUtils.isNotEmpty(task.getTaskId())){
         ApiResult arr = activitiManageDubboService.next(vo.getInstanceId(),vo.getTaskId(),vo.getTaskStatus(),loginInfo);
         ActivitiResult ar = (ActivitiResult)arr.getData();
         if(ar.getActivitiStatus()== com.yunxi.core.base.Constant.ACTIVITI_OVER){
            cancelAuditAgree(vo, loginInfo);
         }else{
            return ResponseUtil.ok("财务同意，流程未结束");
         }
      }else{
         return ResponseUtil.ok("财务同意，任务没有找到");
      }
      return ResponseUtil.ok("财务同意，流程结束");
   }

   @Transactional(rollbackFor = Exception.class)
   @Override
   public ApiResult cancelAuditNext(OrderCustomerVO v, LoginInfo loginInfo) throws InvocationTargetException, IllegalAccessException {

      ApiResult arr = activitiManageDubboService.next(v.getInstanceId(),v.getTaskId(),v.getTaskStatus(),loginInfo);
      String taskName = ((ActivitiResult)arr.getData()).getLastTaskName();
      //需要向APP发起小区经理审批完成的信息
      //PMS→APP	小订退订审核
      if(taskName.equals("城市辅导经理")){
         if ("true".equals(is2App)) {
            if(v.getTaskStatus().equals("AGREE")){
               v.setCancelAudit(2);
            }else if(v.getTaskStatus().equals("REFUSE")){
               v.setCancelAudit(3);
            }
            ApiResult apiResult = cancelAuditPMS2App(v,false,loginInfo);
            if (apiResult!=null) return apiResult;
         }
      }else if(taskName.equals("销售顾问驳回")){
         //流程走完
         //发送APP审核接口
         if(v.getTaskStatus().equals("AGREE")){
            v.setCancelAudit(2);
            this.cancelAuditPMS2App(v,true,loginInfo);
         }else if(v.getTaskStatus().equals("REFUSE")){
            v.setCancelAudit(3);
            this.cancelAuditPMS2App(v,false,loginInfo);
         }
         System.out.println("销售顾问驳回最后一步");
         //发送消息给app
      }else if(taskName.equals("城市辅导经理驳回")){
         //流程走完
         //发送APP审核接口
         if(v.getTaskStatus().equals("AGREE")){
            v.setCancelAudit(2);
            this.cancelAuditPMS2App(v,true,loginInfo);
         }else if(v.getTaskStatus().equals("REFUSE")){
            v.setCancelAudit(3);
            this.cancelAuditPMS2App(v,false,loginInfo);
         }
         System.out.println("城市辅导经理驳回"+v.getTaskStatus());
      }
      return ResponseUtil.ok("常规流程下一步");
   }

   @Override
   public List<OrderActualSalesRespVO> listByVinAndCity(OrderCustomerVO vo) {
      return orderCustomerService.listByVinAndCity(vo);
   }

   @Transactional(rollbackFor = Exception.class)
   @Override
   public ApiResult xiaoqu2app(OrderCustomerVO v, LoginInfo loginInfo) throws InvocationTargetException, IllegalAccessException {

      OrderCustomer oc = orderCustomerService.getById(v.getOrderCustomerId());
      oc.setCancelAudit(2);
      ApiResult apiResult = cancelAuditPMS2App(v,true,loginInfo);
      if (apiResult!=null) return apiResult;
      return ResponseUtil.ok();
   }

   @Transactional(rollbackFor = Exception.class)
   @Override
   public ApiResult autoNext(OrderCustomerVO v, LoginInfo loginInfo) throws InvocationTargetException, IllegalAccessException {
      ActivitiTaskVO task = activitiManageDubboService.getCurTaskIdByBusinessKey(v.getOrderCustomerId());
      v.setInstanceId(task.getInstanceId());
      v.setTaskId(task.getTaskId());
      v.setTaskStatus("AGREE");
      if(task.getTaskName().equals("销售顾问")){
         return cancelAuditNext(v,loginInfo);
      }
      return ResponseUtil.fail(201,"确认失败！");
   }

    @Override
    @Transactional
    public ApiResult assignCar(OrderCustomerVO orderCustomerVO, LoginInfo loginInfo) throws Exception {
        OrderCustomer orderCustomer = new OrderCustomer();
        QueryWrapper<OrderCustomer> wrapper = new QueryWrapper<>();
        wrapper.eq("ORDER_NO", orderCustomerVO.getOrderNo());
        OrderCustomer old = orderCustomerService.getOne(wrapper);
        if (!old.getBusType().equals(1)) {
            return ResponseUtil.fail(4000, "非大定订单,不可配车");
        }

        if (old.getIsCancel() == 1) {
            return ResponseUtil.fail(-1, "该订单已发起退订");
        }
        if (StringUtils.isNotEmpty(old.getVin())) {
            return ResponseUtil.fail(-1, "该订单已配车");
        }
        OrderVehicleVO orderVehicleVO = new OrderVehicleVO();
        orderVehicleVO.setCustomOrderNo(orderCustomerVO.getOrderNo());
        List<OrderVehicleVO> list = orderVehicleService.listByVo(orderVehicleVO);
        if (list != null && list.size() > 0) {
            return ResponseUtil.fail(-1, "该订单已绑定订货单");
        }

        //20190922 更新批售单绑定
        LambdaQueryWrapper<OrderVehicle> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(OrderVehicle::getVin, orderCustomerVO.getVin());
        OrderVehicle orderVehicle = orderVehicleService.getOne(lambdaQueryWrapper);
        if (orderVehicle != null) {
            orderVehicle.setCustomOrderNo(orderCustomerVO.getOrderNo());
            orderVehicleService.updateById(orderVehicle);
        }

//      BeanUtils.copyProperties(old,orderCustomer);
        orderCustomer.setOrderCustomerId(old.getOrderCustomerId());
        orderCustomer.setVin(orderCustomerVO.getVin());
        //将配车信息传入中台
        if ("true".equals(is2Center)) {
            OrderReqDto orderReqDto = setCenterOrderCustomer(orderCustomerVO);
            orderReqDto.setUpdatePerson(loginInfo.getRealName());
            ApiResult apiResult = pms2CenterUpdate(orderReqDto, GUIDGenerator.getPrimaryKey());
            if (apiResult != null) {
                return apiResult;
            }
        }
       boolean isSuccess = orderCustomerService.updateById(orderCustomer);
        if (!isSuccess){
           throw new Exception("配车冲突,请刷新重试");
        }

       QueryWrapper<VehicleOffline> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("VIN", orderCustomerVO.getVin());
      VehicleOfflineVO vo = vehicleOfflineDubboServiceImpl.getOne(queryWrapper);
      vo.setIsLock(1);//1绑定订单已配车
      //体验次数+1
       if (old.getBuyType()==2){
          Integer experienceCount = vo.getExperienceCount();
          vo.setExperienceCount(++experienceCount);
       }

      vo.setUpdateBy(loginInfo.getUserCode());
      if (StringUtils.isNotEmpty(vo.getVehicleId())) {
         vehicleOfflineDubboServiceImpl.saveOrUpdate(vo);
      }

      //pms -> App 同步订单车辆状态
//      OrderStatusVO orderStatusVO = new OrderStatusVO();
//      orderStatusVO.setZzvin("");//VIN号
//      orderStatusVO.setRpname("");//跟踪站点
//      orderStatusVO.setZpassd("");//过点时间（YYYYYMMDDTTMMSS）
//      orderStatusVO.setStCode("");//状态码
//      orderStatusVO.setOrderStatus("");//订单状态
//      orderStatusVO.setOrderNo("");//订单流水号
//      orderStatusVO.setZobl1("");
//      orderStatusVO.setZobl2("");
//      orderStatusVO.setZobl3("");
//
//
//      appDubboServiceImpl.sendOrderStatusPMS2APP(orderStatusVO);


      return ResponseUtil.ok();
   }

   /**
    * 零售转批售
    * @param v
    * @param loginInfo
    * @return
    */
   @Override
   public ApiResult convertBatch(OrderCustomerExOrderOemSaveReqVO v, LoginInfo loginInfo) {

      //boolean b = orderOemManagerDubboServiceImpl.savePmsOrderOem(v);

      return orderOemManagerDubboServiceImpl.saveByOrderCustomer(v, loginInfo);
   }

   @Override
   public List<String> getCustomerNo(OrderCustomerExOrderOemSaveReqVO v) {
      return orderCustomerService.getCustomerNo(v);
   }

   /**
    * 退订申请
    * @param cancelVOAPP
    * @return
    * @throws Exception
    */
   @Override
   @Transactional
   public ApiResult cancelApply(CancelVOAPP cancelVOAPP) throws Exception {

      /** 根据单号查询订单信息 */
      OrderCustomerVO vo = orderCustomerService.getByOrderCustomerNo(cancelVOAPP.getOrderNo());
      if (vo==null) return ResponseUtil.fail( -1,"没有该订单:"+cancelVOAPP.getOrderNo()+"");
      if (vo.getOrderStatus().intValue() !=2 ) return ResponseUtil.fail( -1,"当前订单状态无法申请退订:"+vo.getOrderStatus());

      TrRefundVO trRefundVO = new TrRefundVO();
      trRefundVO.setRefundNo(cancelVOAPP.getRefundOrderNo());
      List<TrRefundVO> list = trRefundService.listByVo(trRefundVO);
      if (list!=null && list.size()>0){return ResponseUtil.fail(-1,"退款申请单号已存在:"+cancelVOAPP.getRefundOrderNo());}

      TrRefundVO RefundVO = new TrRefundVO();
      RefundVO.setOrderId(cancelVOAPP.getOrderNo());
      list = trRefundService.listByVo(RefundVO);
      if (list!=null && list.size()>0){
         for (TrRefundVO refundVO : list) {
            if (refundVO.getStatus().intValue()==1 || refundVO.getStatus().intValue()==2) return ResponseUtil.fail(-1,"该订单已发起退款申请:"+trRefundVO.getOrderId());
         }
      }

      vo.setCancelReason(cancelVOAPP.getComment());//退订原因
      vo.setCancelAudit(cancelVOAPP.getRefundStatus());//退款标志 0-> 申请中 1->已退款 2->退款失败 3->已取消 4财务拒绝 5 财务同意
      vo.setRefundOrderNo(cancelVOAPP.getRefundOrderNo()); //退款申请单号

      LoginInfo loginInfo = new LoginInfo();
      loginInfo.setUserCode("app退订申请");
      OrderCustomer one = new OrderCustomer();
      BeanUtils.copyProperties(vo,one);

      one.setCancelDate(WgrDate.getCurrentDate());
      one.setCancelAudit(DMSEnumsEntity.OrderCancelStatus.WAIT.getKey());
      one.setIsCancel(1);
      one.setOrderStatus(7);
      one.setUpdateBy(loginInfo.getUserCode());
      if (StringUtils.isEmpty(one.getRefundOrderNo()) ){
         one.setRefundOrderNo(GUIDGenerator.getGUID());
      }
      orderCustomerService.cancelApply(one);
      ApiResult flowAr = null;
      if(StringUtils.isNotEmpty(vo.getPartnerCode())&&StringUtils.isNotEmpty(vo.getSalesConsultantNo())){
         //Guan 启动流程
         flowAr = activitiManageDubboService.start("tuiding",one.getOrderCustomerId(),loginInfo);
      }else{
         /** 启动小区退订流程 */
         flowAr = activitiManageDubboService.start("tuidingxiaoqu",one.getOrderCustomerId(),loginInfo);
      }
      if (flowAr==null) return ResponseUtil.fail(-1,"流程启动失败");
      if(flowAr.getCode()==1000) return ResponseUtil.ok(flowAr.getMsg());

      TrRefund trRefund = setRefund(vo);
      if (flowAr.getCode()==200){
         Object data = flowAr.getData();
         if (data==null) return ResponseUtil.fail(-1,"流程启动失败data为空");
         HashMap map = (HashMap) data;
         if(map.get("instanceId")==null)  return ResponseUtil.fail(-1,"流程启动失败instanceId为空");
         trRefund.setInstanceId(Long.valueOf((String)map.get("instanceId")));
      }
      trRefundService.save(trRefund);
      //中台申请退款
      if ("true".equals(is2Center)) {
         RefundReqDto refundReqDto = setRefundReqDto(vo);
         ApiResult apiResult = pms2CenterapplyRefund(vo, refundReqDto);
         if (apiResult!=null) return apiResult;
      }

      //生成消息
      loginInfo.setUserCode(vo.getSalesConsultantNo());
      sendMsg(loginInfo, vo, "31", 4,"rolePartnerSale");

      //      if ("true".equals(is2URM)){
//         //将零售订单基本信息传入URM
//         OrderInformationTransmissionVO orderInformationTransmissionVO = setOrderInforURM(orderCustomerVO);
//         sendOrderInfo2URM(orderInformationTransmissionVO);
//      }
      return ResponseUtil.ok("申请退订成功");
   }

   @Override
   public ApiResult cancelApplyPC(OrderCustomerVO orderCustomerVO, LoginInfo loginInfo) throws Exception {
      //orderCustomerVO上一步就是有查询复制到vo
      TrRefundVO trRefundVO = new TrRefundVO();
      List list = trRefundService.listByVo(trRefundVO);
      if (list!=null && list.size()>0){return ResponseUtil.fail(-1,"退款申请单号已存在");}

      loginInfo.setUserCode("app退订申请");
      OrderCustomer one = new OrderCustomer();
      BeanUtils.copyProperties(orderCustomerVO,one);

      one.setCancelDate(WgrDate.getCurrentDate());
      one.setCancelAudit(DMSEnumsEntity.OrderCancelStatus.WAIT.getKey());
      one.setIsCancel(1);
      one.setOrderStatus(7);
      one.setUpdateBy(loginInfo.getUserCode());

      if (StringUtils.isEmpty(one.getRefundOrderNo()) ){
         one.setRefundOrderNo(GUIDGenerator.getGUID());
      }
      orderCustomerService.cancelApply(one);
      //Guan 启动流程
      ApiResult flowAr = activitiManageDubboService.start("tuiding",one.getOrderCustomerId(),loginInfo);
      if(flowAr.getCode()==1000) return ResponseUtil.ok(flowAr.getMsg());

      TrRefund trRefund = setRefund(orderCustomerVO);
      if (flowAr.getCode()==200){
         Object data = flowAr.getData();
         HashMap map = (HashMap) data;
         trRefund.setInstanceId(Long.valueOf((String)map.get("instanceId")));
      }
      trRefundService.save(trRefund);
      //中台申请退款
      if ("true".equals(is2Center)) {
         RefundReqDto refundReqDto = setRefundReqDto(orderCustomerVO);
         ApiResult apiResult = pms2CenterapplyRefund(orderCustomerVO, refundReqDto);
         if (apiResult!=null) return apiResult;
      }

      //生成消息
      loginInfo.setUserCode(orderCustomerVO.getSalesConsultantNo());
      sendMsg(loginInfo, orderCustomerVO, "31", 4,"rolePartnerSale");

      return ResponseUtil.ok("退订完成");
   }

   private TrRefund setRefund(OrderCustomerVO v) {
      TrRefund trRefund = new TrRefund();
//      trRefund.setTenantId(0L);
//      trRefund.setInstanceId(0L);
      trRefund.setChannelCode(v.getPartnerCode());
      trRefund.setMemberId(v.getCustomerNo());
      trRefund.setRefundNo(v.getRefundOrderNo());
      trRefund.setOrderId(v.getOrderCustomerNo());
      trRefund.setStatus(1);
//      trRefund.setRefundSubject("");
      trRefund.setRefundType(1);
      trRefund.setRefundPayType(0);
      trRefund.setRefundActualAmt(0.0D);//退款金额
      trRefund.setRefundTotalAmt(0.0D);//退款商品金额
      trRefund.setRefundItemNum(0);//退款商品数量
      trRefund.setRefundReason(v.getCancelReason());//退款原因
      trRefund.setBankId("");//开户银行id
      trRefund.setBankBranchId("");//开户银行支行id
      trRefund.setAccountNo("");//银行账户
      trRefund.setAccountName("");//银行账户名称
      trRefund.setRefundExplain("");//退款说明
      trRefund.setRejectReason("");//拒绝原因
      trRefund.setRejectExplain("");//拒绝说明
      trRefund.setApplyTime(new Date());//申请时间
      trRefund.setFirstExamineTime(new Date());//初审时间
      trRefund.setExamineTime(new Date());//审核时间
      trRefund.setPaymentTime(new Date());//退款时间
      trRefund.setCloseTime(new Date());//关闭时间
      trRefund.setRefundOrderType(0);//退款类型1.特惠车订单退款
      trRefund.setContactName("");//联系人姓名
      trRefund.setContactPhone("");//联系人手机
      trRefund.setIsCancel(0);//是否取消 0：未取消 1：已取消
      trRefund.setCancelTime(new Date());//取消时间
      trRefund.setCancelReason("");//取消原因
      trRefund.setDr(0);
      trRefund.setCreateTime(new Date());
      trRefund.setCreatePerson("app");
      trRefund.setUpdatePerson("app");
      trRefund.setUpdateTime(new Date());
      return trRefund;
   }

   private void sendMsg(LoginInfo loginInfo, OrderCustomerVO orderCustomerVO, String msgType, Integer templateType,String receiveRoleCode) throws InvocationTargetException, IllegalAccessException {
      SatMessAddVO satMessAddVO = new SatMessAddVO();
      satMessAddVO.setType(msgType);
      satMessAddVO.setTemplateType(templateType);

      satMessAddVO.setCustomerName(orderCustomerVO.getCustomerName());
      satMessAddVO.setCustomerNo(orderCustomerVO.getCustomerNo());

      satMessAddVO.setSalesConsultantNo(loginInfo.getUserCode());
      satMessAddVO.setOperaRoleCode(loginInfo.getRoleCode());
      satMessAddVO.setReceiveRoleCode(receiveRoleCode);
      satMessAddVO.setBusinessKey(orderCustomerVO.getOrderCustomerNo());
      satMessServiceImpl.newMess(satMessAddVO);
   }

   /**
    * 退订审核
    *  @param v
    * @param loginInfo
    * @return
    */
   @Override
   @Transactional
   public ApiResult cancelAuditAgree(OrderCustomerVO v, LoginInfo loginInfo) throws InvocationTargetException, IllegalAccessException {
      //零售订单主表更新
      v.setCancelAudit(2);
      OrderCustomer oc = orderCustomerService.getById(v.getOrderCustomerId());
      oc.setCancelAudit(v.getCancelAudit());
      oc.setAuditUserId(loginInfo.getUserId());
      oc.setAuditDate(WgrDate.getCurrentDate());
      oc.setUpdateBy(loginInfo.getUserCode());
      //执行退订回滚方法
      oc = callBackCancel(oc, loginInfo);
      oc.setOrderStatus(10);//同意取消
      oc.setIsCancel(1);
      orderCustomerService.updateCancel(oc);

      //中台退款审核接口
      OrderCustomerVO orderCustomerVO = new OrderCustomerVO();
      if ("true".equals(is2Center)) {
            BeanUtils.copyProperties(oc, orderCustomerVO);
            RefundReqDto refundReqDto = setRefundReqDto(orderCustomerVO);
            if (StringUtils.isEmpty(v.getOutTradeNo())) {
               orderCustomerVO.setOutTradeNo(GUIDGenerator.getPrimaryKey());
            }
            ApiResult apiResult = pms2CenterAuditRefund(orderCustomerVO, refundReqDto);
            if (apiResult!=null) return apiResult;
      }

      //PMS→APP
      if ("true".equals(is2App)) {
         ApiResult apiResult = null;//cancelAuditPMS2App(v,true,loginInfo);

         AppLittleOrderAuditVO appLittleOrderAuditVO = new AppLittleOrderAuditVO();
         appLittleOrderAuditVO.setOrder_status("10");
         if (v.getCancelAudit().equals(DMSEnumsEntity.OrderCancelStatus.PASS.getKey())) {
            appLittleOrderAuditVO.setOrder_status("10");
         }else if (v.getCancelAudit().equals(DMSEnumsEntity.OrderCancelStatus.UNPASS.getKey())) {
            appLittleOrderAuditVO.setOrder_status("11");
         }

         if(v.getCustomerNo()==null||v.getRefundOrderNo()==null){
            System.out.println("发现没有值，我在查一次");
            OrderCustomerVO aaa = getById(v.getOrderCustomerId());
            if(aaa!=null){
               v.setCustomerNo(aaa.getCustomerNo());
               v.setRefundOrderNo(aaa.getRefundOrderNo());
            }
         }

         appLittleOrderAuditVO.setOrder_no(v.getOrderCustomerNo());
         appLittleOrderAuditVO.setUserId(v.getCustomerNo());
         appLittleOrderAuditVO.setRefundOrderNo(v.getRefundOrderNo());
         List<AuditRecordVO> arList = new ArrayList<AuditRecordVO>();
         List listRecord = activitiManageDubboService.listRecordByBusinessKey(v.getOrderCustomerId());

         //重新封裝輸出一件列表
         for(int i=0;i<listRecord.size();i++){
            ActivitiRecordVO arv = (ActivitiRecordVO)listRecord.get(i);
            AuditRecordVO ar = new AuditRecordVO();
            ar.setAuditDesc(arv.getAuditDesc());
            System.out.println("遍历审核人 = "+arv.getRealName());
            ar.setAuditName(arv.getRealName());
            if(arv.getAuditStatus().intValue()== Constant.AUDIT_AGREE){
               ar.setAuditStatus("10");
            }else if(arv.getAuditStatus().intValue()==Constant.AUDIT_REFUSE){
               ar.setAuditStatus("11");
            }else if(arv.getAuditStatus().intValue()==Constant.AUDITING){
               ar.setAuditStatus("10");
            }
            ar.setAuditTime(WgrDate.date2Str(arv.getAuditDate(),"yyyy-MM-dd HH:mm:ss"));
            ar.setAuditPosition(arv.getRoleName());
            arList.add(ar);
         }
         appLittleOrderAuditVO.setAuditList(arList);

         try {
            System.out.println(JSONObject.toJSON(appLittleOrderAuditVO));
            apiResult = appDubboServiceImpl.auditAppLittleOrder(appLittleOrderAuditVO);
         } catch (Exception e) {
            logger.error("APP接口调用，小订退订审核传入APP失败，事务回滚!" + e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResponseUtil.fail(-1, "APP接口调用失败:" + e.getMessage());
         }
         if (apiResult.getCode() != 200) {
            logger.error("APP接口执行，小订退订审核传入APP失败，事务回滚!"+apiResult.getCode());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResponseUtil.fail(-1, "APP接口执行失败:" + apiResult.getMsg());
         }
         if (apiResult!=null) return apiResult;
      }
      return ResponseUtil.ok("退订审核完成");
   }

   private ApiResult cancelAuditPMS2App(OrderCustomerVO vo,boolean isEnd,LoginInfo loginInfo) throws InvocationTargetException, IllegalAccessException {
      ApiResult apiResult = null;

      AppLittleOrderAuditVO appLittleOrderAuditVO = new AppLittleOrderAuditVO();
      appLittleOrderAuditVO.setOrder_status("10");
      if(vo.getCancelAudit()==null){
         vo.setCancelAudit(2);
      }

      if (vo.getCancelAudit().equals(DMSEnumsEntity.OrderCancelStatus.PASS.getKey())) {
         appLittleOrderAuditVO.setOrder_status("10");
      }else if (vo.getCancelAudit().equals(DMSEnumsEntity.OrderCancelStatus.UNPASS.getKey())) {
         appLittleOrderAuditVO.setOrder_status("11");
      }

      if(vo.getCustomerNo()==null||vo.getRefundOrderNo()==null){
         System.out.println("发现没有值，我在查一次");
         OrderCustomerVO aaa = getById(vo.getOrderCustomerId());
         if(aaa!=null){
            vo.setCustomerNo(aaa.getCustomerNo());
            vo.setRefundOrderNo(aaa.getRefundOrderNo());
         }
      }

      appLittleOrderAuditVO.setOrder_no(vo.getOrderCustomerNo());
      appLittleOrderAuditVO.setUserId(vo.getCustomerNo());
      appLittleOrderAuditVO.setRefundOrderNo(vo.getRefundOrderNo());
      System.out.println("是否结束 = "+isEnd);
      if(isEnd){
         List<AuditRecordVO> arList = new ArrayList<AuditRecordVO>();
         List listRecord = activitiManageDubboService.listRecordByBusinessKey(vo.getOrderCustomerId());

         //重新封裝輸出一件列表
         for(int i=0;i<listRecord.size();i++){
            ActivitiRecordVO arv = (ActivitiRecordVO)listRecord.get(i);
            AuditRecordVO ar = new AuditRecordVO();
            ar.setAuditDesc(arv.getAuditDesc());
            System.out.println("遍历审核人 = "+arv.getRealName());
            ar.setAuditName(arv.getRealName());
            if(arv.getAuditStatus().intValue()== Constant.AUDIT_AGREE){
               ar.setAuditStatus("10");
            }else if(arv.getAuditStatus().intValue()==Constant.AUDIT_REFUSE){
               ar.setAuditStatus("11");
            }else if(arv.getAuditStatus().intValue()==Constant.AUDITING){
               ar.setAuditStatus("10");
            }
            ar.setAuditTime(WgrDate.date2Str(arv.getAuditDate(),"yyyy-MM-dd HH:mm:ss"));
            ar.setAuditPosition(arv.getRoleName());
            arList.add(ar);
         }
         appLittleOrderAuditVO.setAuditList(arList);
      }

      try {
         System.out.println(JSONObject.toJSON(appLittleOrderAuditVO));
         //apiResult.setData(appLittleOrderAuditVO);
         apiResult = appDubboServiceImpl.auditAppLittleOrder(appLittleOrderAuditVO);
      } catch (Exception e) {
         logger.error("APP接口调用，小订退订审核传入APP失败，事务回滚!" + e.getMessage());
         if(TransactionAspectSupport.currentTransactionStatus()!=null){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         }
         e.printStackTrace();
         return ResponseUtil.fail(-1, "APP接口调用失败:" + e.getMessage());
      }
      if (apiResult.getCode() != 200) {
         logger.error("APP接口执行，小订退订审核传入APP失败，事务回滚!"+apiResult.getCode());
         if(TransactionAspectSupport.currentTransactionStatus()!=null){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         }
         return ResponseUtil.fail(-1, "APP接口执行失败:" + apiResult.getMsg());
      }
      //订单审核驳回传入中台
      if ("true".equals(is2Center)){
         OrderCustomer oc = orderCustomerService.getById(vo.getOrderCustomerId());
         oc.setCancelAudit(vo.getCancelAudit());
         oc.setAuditUserId(loginInfo.getUserId());
         oc.setAuditDate(WgrDate.getCurrentDate());
         oc.setUpdateBy(loginInfo.getUserCode());
         if (oc.getCancelAudit().equals(DMSEnumsEntity.OrderCancelStatus.PASS.getKey())) {
            //执行退订回滚方法
            oc = callBackCancel(oc, loginInfo);
            oc.setOrderStatus(10);//同意取消
            oc.setIsCancel(1);
         }
         else if (oc.getCancelAudit().equals(DMSEnumsEntity.OrderCancelStatus.UNPASS.getKey())) {
            oc.setOrderStatus(11);//驳回取消
            oc.setIsCancel(0);
         }
         orderCustomerService.updateCancel(oc);
         //中台退款审核接口
         OrderCustomerVO orderCustomerVO = new OrderCustomerVO();
         BeanUtils.copyProperties(oc, orderCustomerVO);
         RefundReqDto refundReqDto = setRefundReqDto(orderCustomerVO);
         if (StringUtils.isEmpty(vo.getOutTradeNo())) {
            orderCustomerVO.setOutTradeNo(GUIDGenerator.getPrimaryKey());
         }
         apiResult = pms2CenterAuditRefund(orderCustomerVO, refundReqDto);
         if (apiResult!=null)
            return apiResult;
      }
      return ResponseUtil.ok("退订审核完成");
   }

   public ApiResult pms2appOnly(String orderCustomerNo,Integer result,boolean isEnd){
      ApiResult apiResult = null;
      AppLittleOrderAuditVO appLittleOrderAuditVO = new AppLittleOrderAuditVO();

      OrderCustomerVO oc = orderCustomerService.getByOrderCustomerNo(orderCustomerNo);

      appLittleOrderAuditVO.setOrder_status("10");
      if (result.equals(DMSEnumsEntity.OrderCancelStatus.UNPASS.getKey())) {
         appLittleOrderAuditVO.setOrder_status("11");
      }

      appLittleOrderAuditVO.setOrder_no(oc.getOrderCustomerNo());
      appLittleOrderAuditVO.setUserId(oc.getCustomerNo());
      appLittleOrderAuditVO.setRefundOrderNo(oc.getRefundOrderNo());


      if(isEnd){
         List<AuditRecordVO> arList = new ArrayList<AuditRecordVO>();
         List listRecord = activitiManageDubboService.listRecordByBusinessKey(oc.getOrderCustomerId());

         //重新封裝輸出一件列表
         for(int i=0;i<listRecord.size();i++){
            ActivitiRecordVO arv = (ActivitiRecordVO)listRecord.get(i);
            AuditRecordVO ar = new AuditRecordVO();
            ar.setAuditDesc(arv.getAuditDesc());
            System.out.println("遍历审核人 = "+arv.getRealName());
            ar.setAuditName(arv.getRealName());
            if(arv.getAuditStatus().intValue()== Constant.AUDIT_AGREE){
               ar.setAuditStatus("10");
            }else if(arv.getAuditStatus().intValue()==Constant.AUDIT_REFUSE){
               ar.setAuditStatus("11");
            }else if(arv.getAuditStatus().intValue()==Constant.AUDITING){
               ar.setAuditStatus("10");
            }
            ar.setAuditTime(WgrDate.date2Str(arv.getAuditDate(),"yyyy-MM-dd HH:mm:ss"));
            ar.setAuditPosition(arv.getRoleName());
            arList.add(ar);
         }
         appLittleOrderAuditVO.setAuditList(arList);
      }

      System.out.println(JSONObject.toJSON(appLittleOrderAuditVO));
         //apiResult.setData(appLittleOrderAuditVO);
      apiResult.setData(appLittleOrderAuditVO);
      apiResult = appDubboServiceImpl.auditAppLittleOrder(appLittleOrderAuditVO);
      if (apiResult.getCode() != 200) {
         logger.error("APP接口执行，小订退订审核传入APP失败，事务回滚!"+apiResult.getCode());
         if(TransactionAspectSupport.currentTransactionStatus()!=null){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         }
         return ResponseUtil.fail(-1, "APP接口执行失败:" + apiResult.getMsg());
      }
      return apiResult;
   }

    @Override
    public ApiResult exportOrder(OrderCustomerVO orderCustomerVO,LoginInfo loginInfo) {
      if (StringUtils.isNotEmpty(loginInfo.getPartnerCode())){
         orderCustomerVO.setPartnerCode(loginInfo.getPartnerCode());
      }
        List<OrderCustomerExportVO> list = orderCustomerService.exportOrder(orderCustomerVO);
        return ResponseUtil.ok(list);
    }

    private ApiResult pms2CenterapplyRefund(OrderCustomerVO v, RefundReqDto refundReqDto) {
      RestResponse<Void> voidRestResponse = null;
      try {
         //将渠道信息传入中台
         voidRestResponse = refundApi.applyRefund(GUIDGenerator.getPrimaryKey(), refundReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错 _ pms2CenterapplyRefund __<中台申请退款>-" + e.getMessage());
         e.printStackTrace();
         if (this.getChinesses(e.getMessage())!=null){
            return ResponseUtil.fail(-1,"中台调用出错___<中台申请退款>-" + this.getChinesses(e.getMessage()));
         }
         return ResponseUtil.fail(-1,"中台调用出错:"+e.getMessage());
      }
      if (!voidRestResponse.getResultCode().equals("0")) {
         if(TransactionAspectSupport.currentTransactionStatus()!=null){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         }
         logger.error(" ------- 中台执行失败 _ pms2CenterapplyRefund __<中台申请退款>-" + voidRestResponse.getResultMsg());
         return ResponseUtil.fail(-1,"中台执行出错:"+ voidRestResponse.getResultMsg());
      }
      return null;
   }

   private ApiResult pms2CenterCancelRefund(OrderCustomerVO v, RefundReqDto refundReqDto) {
      RestResponse<Void> voidRestResponse = null;
      try {
         //将渠道信息传入中台
         voidRestResponse = refundApi.cancelRefund(GUIDGenerator.getPrimaryKey(), refundReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错 _ pms2CenterCancelRefund __<中台取消退订>-" + e.getMessage());
         e.printStackTrace();
         if (this.getChinesses(e.getMessage())!=null){
            return ResponseUtil.fail(-1,"中台调用出错___<中台取消退订>-" + this.getChinesses(e.getMessage()));
         }
         return ResponseUtil.fail(-1,"中台调用出错:"+e.getMessage());
      }
      if (!voidRestResponse.getResultCode().equals("0")) {
         if(TransactionAspectSupport.currentTransactionStatus()!=null){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         }
         logger.error(" ------- 中台执行失败 _ pms2CenterCancelRefund __<中台取消退订>-" + voidRestResponse.getResultMsg());
         return ResponseUtil.fail(-1,"中台执行失败:"+ voidRestResponse.getResultMsg());
      }
      return null;
   }

   private ApiResult pms2CenterAuditRefund(OrderCustomerVO v, RefundReqDto refundReqDto) {
      RestResponse<Void> voidRestResponse = null;
         //将渠道信息传入中台
      voidRestResponse = refundApi.auditRefund(GUIDGenerator.getPrimaryKey(), refundReqDto);
      if (!voidRestResponse.getResultCode().equals("0")) {
         if(TransactionAspectSupport.currentTransactionStatus()!=null){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         }
         logger.error(" ------- 中台执行失败 _ pms2CenterAuditRefund __<中台退款审核>-" + voidRestResponse.getResultMsg());
         return ResponseUtil.fail(-1,"中台调用出错" + voidRestResponse.getResultMsg());
      }
      return null;
   }

   private RefundReqDto setRefundReqDto(OrderCustomerVO orderCustomerVO) {
      RefundReqDto refundReqDto = new RefundReqDto();
      refundReqDto.setChannelCode(orderCustomerVO.getPartnerCode());//渠道编码
      refundReqDto.setMemberId(orderCustomerVO.getCustomerId());//用户ID
      refundReqDto.setRefundNo(orderCustomerVO.getRefundOrderNo());//退款单号
      refundReqDto.setOrderId(orderCustomerVO.getOrderNo());//订单ID
      refundReqDto.setStatus(orderCustomerVO.getCancelAudit());//申请状态 1待审核 2审核通过 3审核驳回
      refundReqDto.setRefundSubject("");//退款主题
      refundReqDto.setRefundType(1);//退款申请类别 1退款  2退货退款 3异常退款 4仅退款
      refundReqDto.setRefundPayType(1);//退款付款方式 1.线下汇款 2.现金支付 3.刷卡支付 4.在线支付
      refundReqDto.setRefundActualAmt(1.00);//退款金额
      refundReqDto.setRefundTotalAmt(1.00);//退款商品金额
      refundReqDto.setRefundItemNum(orderCustomerVO.getNum());//退款商品数量
      refundReqDto.setRefundReason(orderCustomerVO.getCancelReason());//退款原因
      refundReqDto.setBankId("2342353425");//开户银行id
      refundReqDto.setBankBranchId("33333");//开户银行支行id
      refundReqDto.setAccountNo("43532456346");//银行账户
      refundReqDto.setAccountName("xxx");//银行账户名称
      refundReqDto.setRefundExplain("");//退款说明
      refundReqDto.setRejectReason("");//拒绝原因
      refundReqDto.setRejectExplain("");//拒绝说明
      refundReqDto.setApplyTime(new Date());//申请时间
      refundReqDto.setFirstExamineTime(new Date());//初审时间
      refundReqDto.setExamineTime(new Date());//审核时间
      refundReqDto.setPaymentTime(new Date());//退款时间
      refundReqDto.setCloseTime(new Date());//关闭时间
      refundReqDto.setRefundOrderType(1);//退款类型1.特惠车订单退款
      refundReqDto.setContactName(orderCustomerVO.getCustomerName());//联系人姓名
      refundReqDto.setContactPhone(orderCustomerVO.getCustomerMobile());//联系人手机
      refundReqDto.setIsCancel(orderCustomerVO.getIsCancel());//是否取消 1：未取消 2：已取消
      refundReqDto.setCancelTime(orderCustomerVO.getCancelDate());//取消时间
      refundReqDto.setCancelReason(orderCustomerVO.getCancelReason());//取消原因
      return refundReqDto;
   }


   /**
    * 配车解绑 订货单中的零售订单号清空
    * @param oc
    * @param loginInfo
    * @return
    */
   private OrderCustomer callBackCancel(OrderCustomer oc, LoginInfo loginInfo) {
      //1、零售订单 orderStatus状态更新为6 vin码清空
      if (StringUtils.isNotEmpty(oc.getVin())) {
         String vin = oc.getVin();
         oc.setVin(null);


         //2、下线车辆表 isLock锁定状态更新为0
         VehicleOfflineVO voo = new VehicleOfflineVO();
         voo.setVin(vin);
         voo.setIsLock(0);
         voo.setUpdateBy(loginInfo.getUserCode());
         vehicleOfflineDubboService.updateByVin(voo);
      }

      //3、订货单中的零售订单号清空
      orderVehicleService.unBandCustomOrderNo(oc.getOrderCustomerNo(), oc.getUpdateBy());
      return oc;
   }

   /**
    * 关联订货单
    * @param v
    * @param loginInfo
    */
   @Override
   public void relateOrderVehicle(OrderCustomerVO v, LoginInfo loginInfo) {
      OrderVehicle ov = new OrderVehicle();
      ov.setOrderCarId(v.getOrderCarId());
      ov.setCustomOrderNo(v.getOrderNo());
      ov.setUpdateBy(loginInfo.getUserCode());
      orderVehicleService.bandCustomOrderNoByOrderId(ov);
   }

   /**
    * 销售顾问本月全部订单
    *
    * @param orderCustomerVO
    * @param loginInfo
    * @return
    * @throws Exception
    */
   @Override
   public List<OrderCustomerVO> allList(OrderCustomerVO orderCustomerVO, LoginInfo loginInfo) throws Exception {

      orderCustomerVO.setPartnerCode(loginInfo.getPartnerCode());
      // 非总经理、非销售经理则按登录账号查询
      if (StringUtils.isNotEmpty(loginInfo.getRoleCode()) && !DictConstant.USER_ROLE_MANAGER
          .equals(loginInfo.getRoleCode()) && !DictConstant.USER_ROLE_PARTNER_MANAGER
          .equals(loginInfo.getRoleCode())) {
         orderCustomerVO.setSalesConsultantNo(loginInfo.getUserCode());
      }
      orderCustomerVO.setCreateTime(new Date());
      return orderCustomerService.allList(orderCustomerVO);
   }

   @Override
   public void updateBatch(List<OrderCustomerVO> orderCustomerVOList) throws IllegalAccessException, InvocationTargetException, InstantiationException {
      for (OrderCustomerVO orderCustomerVO : orderCustomerVOList) {
         OrderCustomer orderCustomer = new OrderCustomer();
         BeanUtils.copyProperties(orderCustomerVO, orderCustomer);
         orderCustomerService.assignSaler(orderCustomer);
      }
   }

   @Override
   public List listAllByCustomerNo(OrderCustomerVO v, LoginInfo loginInfo) {
      if (loginInfo.getPartner() != null) {
         PartnerVO partnerVO = JSONObject.parseObject(JSONObject.toJSONString(loginInfo.getPartner()), PartnerVO.class);
         v.setPartnerCode(partnerVO.getPartnerCode());
         if (loginInfo.getStaff() != null) {
            if (DictConstant.USER_ROLE_SALES.equals(loginInfo.getRoleCode())) {
               v.setSalesConsultantNo(loginInfo.getUserCode());
            }

            if (DictConstant.USER_ROLE_MANAGER.equals(loginInfo.getRoleCode())) {
               v.setSalesConsultantNo("");
            }

         }
      } else {
         v.setPartnerCode("");
         v.setSalesConsultantNo("");
      }
      return orderCustomerService.listAllByCustomerNo(v);


   }


   @Override
   public List listByVo(OrderCustomerVO orderCustomerVO, LoginInfo loginInfo) throws Exception {
      if (loginInfo.getPartner() != null) {
         orderCustomerVO.setPartnerCode(loginInfo.getPartnerCode());
         if (DictConstant.USER_ROLE_SALES.equals(loginInfo.getRoleCode())) {
            orderCustomerVO.setSalesConsultantNo(loginInfo.getUserCode());
         }

         if (DictConstant.USER_ROLE_MANAGER.equals(loginInfo.getRoleCode())) {
//               orderCustomerVO.setSalesConsultantNo("");
         }
      } else {
//         if (DictConstant.USER_ROLE_AREAMANAGER.equals(loginInfo.getRoleCode())) {//大区经理
//            AreaManagerVO vo = new AreaManagerVO();
//            vo.setUserCode(loginInfo.getUserCode());
//            List<AreaManagerVO> list = areaManagerDubboServiceImpl.listByVo(vo);
//            if (list != null && list.size() > 0) {
//               orderCustomerVO.setBigRegion(list.get(0).getAreaCode());
//            } else {
//               return null;
//            }
//         }
//         orderCustomerVO.setPartnerCode("");
//         orderCustomerVO.setSalesConsultantNo("");
         orderCustomerVO.setBigRegion(null);
      }

      //
      List<OrderCustomerVO> list = orderCustomerService.listByVo(orderCustomerVO);
      if (list != null && list.size() > 0) {
          List<DictVO> dictList = dict2BizDubboService.getDictListByType("financeType");
         for (OrderCustomerVO vo : list) {
            OrderCustomerDetailVO orderCustomerDetailVO = vo.getOrderCustomerDetailVO();
            if (orderCustomerDetailVO!=null){
               String productName = orderCustomerDetailVO.getVehicleName();
               vo.setProductName(productName);
               if (StringUtils.isNotEmpty(vo.getCustomPackName())){
                  String s = vo.getCustomPackName().replaceAll("\"", "");
                  String packName = s.substring(1, s.length() - 1);
                  vo.setPackName(packName);
               }
            }
            //todo
             //金融类型 key => value
             if(StringUtils.isNotEmpty(vo.getFinProduct())){
                 for(DictVO dictVO:dictList){
                     if(dictVO.getDictKey().equals(vo.getFinProduct())){
                         vo.setFinProduct(dictVO.getDictValue());
                     }
                 }

             }
         }
      }
      return list;
   }

   @Override
   public void removeById(String id) {
      orderCustomerService.removeById(id);
   }

   @Override
   public PageInfo<OrderCustomerVO> findPageByVO(OrderCustomerVO orderCustomerVO, Integer pageNum, Integer pageSize, LoginInfo loginInfo) throws InvocationTargetException, IllegalAccessException {
      //Guan 此处代码段可以跟list公用
      if (loginInfo.getPartner() != null) {
         orderCustomerVO.setPartnerCode(loginInfo.getPartnerCode());
         if (DictConstant.USER_ROLE_SALES.equals(loginInfo.getRoleCode())) {
            orderCustomerVO.setSalesConsultantNo(loginInfo.getUserCode());
         }

         if (DictConstant.USER_ROLE_MANAGER.equals(loginInfo.getRoleCode())) {
//               orderCustomerVO.setSalesConsultantNo("");
         }
      } else {
//         if (DictConstant.USER_ROLE_AREAMANAGER.equals(loginInfo.getRoleCode())) {//大区经理
//            AreaManagerVO vo = new AreaManagerVO();
//            vo.setUserCode(loginInfo.getUserCode());
//            List<AreaManagerVO> list = areaManagerDubboServiceImpl.listByVo(vo);
//            if (list != null && list.size() > 0) {
//               orderCustomerVO.setBigRegion(list.get(0).getAreaCode());
//            } else {
//               return null;
//            }
//         }
//         orderCustomerVO.setPartnerCode("");
//         orderCustomerVO.setSalesConsultantNo("");
         orderCustomerVO.setBigRegion(null);
      }

      if(orderCustomerVO.getOrderNo() != null && orderCustomerVO.getOrderNo().length() > 1){
         orderCustomerVO.setOrderNoPrefix(orderCustomerVO.getOrderNo().substring(0,2));
      }

      PageInfo<OrderCustomerVO> pageInfo = orderCustomerService.pageByVo(orderCustomerVO, pageNum, pageSize);
      List<OrderCustomerVO> list = pageInfo.getList();
      for (OrderCustomerVO vo : list) {
         String customPackName = vo.getCustomPackName();
         if (StringUtils.isNotEmpty(customPackName)){
            String s = customPackName.replaceAll("\"", "");
            String packName = s.substring(1, s.length() - 1);
            vo.setPackName(packName);
         }
      }
      return pageInfo;
   }

   @Override
   public void removeByListVo(List<OrderCustomerVO> orderCustomerVOList) throws IllegalAccessException, InvocationTargetException, InstantiationException {
      orderCustomerService.removeByListVo(orderCustomerVOList);
   }

   @Override
   public OrderCustomerVO load(String orderNo) {
      return orderCustomerService.load(orderNo);
   }

   @Override
   public PageInfo<OrderCustomerExOrderOemSaveReqVO> convertGroupList(Integer pageNum, Integer pageSize, String partnerCode) {

      return orderCustomerService.convertGroupList(pageNum, pageSize, partnerCode);
   }


}
